string2json()

string2json()#

string2json converts a legal JSON string into a json_t object. The input string must be a valid JSON array ([]) or object ({}).

Prototype

json_t *string2json(
    const char *str,
    BOOL verbose
);

Parameters

Key

Type

Description

str

const char *

A null-terminated string containing a valid JSON object or array.

verbose

BOOL

If TRUE, logs errors when parsing fails.


Return Value

Returns a json_t * object if parsing is successful. Returns NULL if parsing fails.

Notes

[‘This function only accepts JSON objects ({}) or arrays ([]).’, ‘For more flexible JSON parsing, use anystring2json().’, ‘The returned json_t * must be freed using json_decref() to avoid memory leaks.’]

Prototype

// Not applicable in JS

Prototype

# Not applicable in Python
Examples
// TODO C examples
// TODO JS examples
# TODO Python examples