Skip to main content

jsonStringify

jsonStringify ( value : any {, *} ) : string

ParameterTypeDescription
valueany->Data to convert into JSON string
*->Pretty printing
Resultstring<-String containing serialized JSON string

Description

The jsonStringify command converts the value parameter into a JSON string. This command performs the opposite action of the jsonParse command.

Pass the data to be serialized in value. It can be expressed in scalar form (string, number, date or time) or by means of a Qodly object or collection

note

Qodly dates will be converted either in "yyyy-mm-dd" or "YYYY-MM-DDThh:mm:sssZ" format according to the current database date setting.

You can pass the optional * parameter to include formatting characters in the resulting string. This improves the presentation of JSON data (known as pretty formatting).

Example 1

Conversion of scalar values:


var vc, vel, vh, vd : string

vc = jsonStringify("Eureka!") // "Eureka!"
vel = jsonStringify(120) // "120"

vh = jsonStringify(?20:00:00?) // "72000" seconds since midnight


vd = jsonStringify(!28/08/2013!) // "2013-08-27T22:00:00.000Z" (Paris timezone)

Example 2

Conversion of a string containing special characters:

var s, p : string

s = jsonStringify("{\"name\":\"john\"}")
// s = "{\\"name\\":\\"john\\"}"
p = jsonParse(s)
// p = {"name":"john"}

See also

jsonParse