For working with JSON strings and objects


Lib.Sys.Json.parse(text)

Parses given JSON-encoded text and returns the resulting object.
If given text is not valid JSON, an exception will be thrown.

text - Json text

Lib.Sys.Json.stringify(value, replacer, space)

Encodes the given value and returns the resulting JSON string.
If replacer is not nil, it is used to retrieve the actual object to be encoded. The replacer function takes two parameters, the key and the value being encoded. Initial key value is an empty string.
If space is not nil, the result will be pretty-printed. Successive levels will be indented by this string.

value - Json object

replacer - function for encoding

space - string, usually set of spacebars for pretty-printing


Examples:


json = Lib.Sys.Json.parse([[{

    "glossary": {

        "title": "example glossary",

               "GlossDiv": {

            "title": "S",

                       "GlossList": {

                "GlossEntry": {

                    "ID": "SGML",

                                       "SortAs": "SGML",

                                       "GlossTerm": "Standard Generalized Markup Language",

                                       "Acronym": "SGML",

                                       "Abbrev": "ISO 8879:1986",

                                       "GlossDef": {

                        "para": "A meta-markup language, used to create markup languages such as DocBook.",

                                               "GlossSeeAlso": ["GML", "XML"]

                    },

                                       "GlossSee": "markup"

                }

            }

        }

    }

}]])


print(json.glossary.title)

print(json.glossary.GlossDiv.GlossList.GlossEntry.GlossDef.GlossSeeAlso[1])

print(Lib.Sys.Json.stringify( json, nil, ' ' ))

Created with the Personal Edition of HelpNDoc: Free help authoring environment