Skip to navigation

JSON encoding and decoding functions.

Members

decode

json.decode(x, default?)

Decodes a JSON string into a Starlark value. JSON objects become dicts, arrays become lists.

Parameters
xstringJSON string to decode
default?optionalanyValue to return if x cannot be decoded as JSON (optional)
Returns
resultanyDecoded Starlark value

encode

json.encode(x)

Encodes a Starlark value as a JSON string. Supports None, bool, int, float, string, dict, list, tuple, and structs.

Parameters
xanyValue to encode as JSON
Returns
resultstringJSON-encoded string

indent

json.indent(s, prefix?, indent?)

Returns the indented form of a JSON-encoded string.

Parameters
sstringJSON string to indent
prefix?optionalstringPrefix for each line (default: empty)
indent?optionalstringIndent string for each level (default: “\t”)
Returns
resultstringIndented JSON string