Hi all,
Unless I'm mistaken, there is no builtin class or function to do it. For the need of my widget (APICall), I coded a function to do it.
I'm not a professionnal developper, so it surely not perfect but do the job.
I followed this description of the grammar : www.json.org/json-fr.html.
But do some minor changes :
- The "name" part of an objet can be defined without "double quote" if start with a letter and have only letter, digit, -, _ or . Ex : {name:"value"} is ok.
- It only accept space as "whitespace", no tab, carrier return etc ... but you can change the function <read_spaces> to change this behavior.
- It accept there is not "whitespace" beetween any element of the grammar.
- It doesn't correctly interprete some escaped characters in a string (\\, \/ and \" are OK, but \b \f \n \r \t and \u are not interpreted).
It's only a set of functions not a class. You just have to call json_to_dict(my_json_str_convert). It will return a dictionnary.
If there is a syntax error, it only return null, it is perhaps the main improvement to do ;o)
Enjoy !
Source code here : https://apicall.dumesnil.net/APICallJson.html