Module json is a Starlark module of JSON-related functions.
json = module( encode, decode, indent, )
def encode(x):
The encode function accepts one required positional argument, which it converts to JSON by cases:
It an application-defined type matches more than one the cases describe above, (e.g. it implements both Iterable and HasFields), the first case takes precedence. Encoding any other value yields an error.
def decode(x[, default]):
The decode function has one required positional parameter, a JSON string. It returns the Starlark value that the string denotes.
If x is not a valid JSON string, the behavior depends on the "default" parameter: if present, Decode returns its value; otherwise, Decode fails.
def indent(str, *, prefix="", indent="\t"):
The indent function pretty-prints a valid JSON encoding, and returns a string containing the indented form. It accepts one required positional parameter, the JSON string, and two optional keyword-only string parameters, prefix and indent, that specify a prefix of each new line, and the unit of indentation.
var Module = &starlarkstruct.Module{ Name: "json", Members: starlark.StringDict{ "encode": starlark.NewBuiltin("json.encode", encode), "decode": starlark.NewBuiltin("json.decode", decode), "indent": starlark.NewBuiltin("json.indent", indent), }, }