JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. It is based on a subset of the JavaScript Programming Language, Standard ECMA-262 3rd Edition - December 1999. JSON is a text format that is completely language independent but uses conventions that are familiar to programmers of the C-family of languages, including C, C++, C#, Java, JavaScript, Perl, Python, and many others. These properties make JSON an ideal data-interchange language.
JSON is built on two structures:
- A collection of name/value pairs. In various languages, this is realized as an object, record, struct, dictionary, hash table, keyed list, or associative array.
- An ordered list of values. In most languages, this is realized as an array, vector, list, or sequence.
JSON-GLib combines the JSON features with GLib-Object. You can generate a JSON stream directly from an GLib object and vice versa.
Download (version 0.14.2):
Testcode:
Code: Select all
#INCLUDE "json-glib.bi"
g_type_init()
'' create parser
VAR pars = json_parser_new()
'' create pointer for error messages (if any)
DIM AS GError PTR errr
'' some input to test (whitespaces should get removed in output)
VAR t = "{""name"":[[[1,2,3,4],5, 6],7, 8]}"
'var t = "[{""hello"":""hello""}]"
'var t = "[{""hello"":1},{ ""foo"":""what_foo""}] "
'' parse the stream (+ output error if any)
?json_parser_load_from_data(pars, t, LEN(t), @errr)
IF errr THEN ?*errr->message
'' get the root node
VAR node = json_parser_get_root(pars)
'' create generator, set root
VAR gen = json_generator_new()
json_generator_set_root(gen, node)
'' generate output (should be equal to input)
?*json_generator_to_data(gen, 0)
'' free memory
g_object_unref(gen)
g_object_unref(pars)