Qore JSON Module  1.8
JSON Functions

Functions

string Qore::Json::makeFormattedJSONString (any data, *string encoding)
 Serializes qore data into a JSON string, formatted with line breaks for easier readability. More...
 
string Qore::Json::makeJSONString (any data, *string encoding)
 Serializes qore data into a JSON string, without any line breaks. More...
 
string Qore::Json::make_json (any data, *int format, *string encoding)
 Serializes qore data into a JSON string with optional whitespace formatting (line breaks and indentation) More...
 
nothing Qore::Json::parseJSON ()
 This is a variant that is basically a noop, included for backwards-compatibility for functions that ignored type errors in the calling parameters. More...
 
auto Qore::Json::parseJSON (string json_str)
 Parses a JSON string and returns the corresponding Qore data structure. More...
 
auto Qore::Json::parse_json (string json_str)
 Parses a JSON string and returns the corresponding Qore data structure. More...
 

Detailed Description

Function Documentation

◆ make_json()

string Qore::Json::make_json ( any  data,
*int  format,
*string  encoding 
)

Serializes qore data into a JSON string with optional whitespace formatting (line breaks and indentation)

Code Flags:
RET_VALUE_ONLY
Example:
string json = make_json(data);

By default the string produced will be in UTF-8 encoding, but this can be overridden by the encoding argument

Parameters
datathe data to serialize to a JSON string
formatoptional formatting flags; see JSON Generation Constants for more information
encodingan optional output encoding for the resulting JSON string; if this argument is not passed, then UTF-8 encoding is used by default
Returns
the JSON string corresponding to the arguments passed
Exceptions
JSON-SERIALIZATION-ERRORcannot serialize value passed (ex: binary, object)
ENCODING-CONVERSION-ERRORthis exception could be thrown if an error occurs converting input strings to the target encoding
Note
According to RFC 7159 JSON strings can only be in UTF-8, UTF-16, or UTF-32 encoding, but this function will allow any encoding to be used to generate JSON strings
See also
Automatic JSON Serialization and Deserialization
Since
json 1.5 as a replacement for deprecated camel-case makeJSONString() and makeFormattedJSONString()

◆ makeFormattedJSONString()

string Qore::Json::makeFormattedJSONString ( any  data,
*string  encoding 
)

Serializes qore data into a JSON string, formatted with line breaks for easier readability.

By default the string produced will be in UTF-8 encoding, but this can be overridden by the second argument

Code Flags:
RET_VALUE_ONLY, DEPRECATED
Parameters
datathe data to serialize to a JSON string
encodingan optional output encoding for the resulting JSON string; if this argument is not passed, then UTF-8 encoding is used by default
Returns
the JSON string corresponding to the arguments passed, formatted with line breaks for easier readability
Exceptions
JSON-SERIALIZATION-ERRORcannot serialize value passed (ex: binary, object)
Deprecated:
use make_json(); camel-case function names were deprecated in json 1.5
See also
Automatic JSON Serialization and Deserialization

◆ makeJSONString()

string Qore::Json::makeJSONString ( any  data,
*string  encoding 
)

Serializes qore data into a JSON string, without any line breaks.

By default the string produced will be in UTF-8 encoding, but this can be overridden by the second argument

Code Flags:
RET_VALUE_ONLY, DEPRECATED
Parameters
datathe data to serialize to a JSON string
encodingan optional output encoding for the resulting JSON string; if this argument is not passed, then UTF-8 encoding is used by default
Returns
the JSON string corresponding to the arguments passed, without any line breaks
Exceptions
JSON-SERIALIZATION-ERRORcannot serialize value passed (ex: binary, object)
Deprecated:
use make_json(); camel-case function names were deprecated in json 1.5
See also
Automatic JSON Serialization and Deserialization

◆ parse_json()

auto Qore::Json::parse_json ( string  json_str)

Parses a JSON string and returns the corresponding Qore data structure.

Code Flags:
RET_VALUE_ONLY
Parameters
json_strthe JSON string to parse
Returns
the Qore data structure corresponding to the input string
Exceptions
JSON-PARSE-ERRORsyntax error parsing JSON string
Example:
any data = parse_json(json);
See also
Automatic JSON Serialization and Deserialization
Since
json 1.5 as a replacement for deprecated camel-case parseJSON()

◆ parseJSON() [1/2]

nothing Qore::Json::parseJSON ( )

This is a variant that is basically a noop, included for backwards-compatibility for functions that ignored type errors in the calling parameters.

Code Flags:
RUNTIME_NOOP, DEPRECATED

◆ parseJSON() [2/2]

auto Qore::Json::parseJSON ( string  json_str)

Parses a JSON string and returns the corresponding Qore data structure.

Code Flags:
RET_VALUE_ONLY, DEPRECATED
Parameters
json_strthe JSON string to parse
Returns
the Qore data structure corresponding to the input string
Exceptions
JSON-PARSE-ERRORsyntax error parsing JSON string
See also
Automatic JSON Serialization and Deserialization
Deprecated:
use parse_json(); camel-case function names were deprecated in json 1.5