Skip to content

Json Parser

Spice
import "std/text/json-parser";

JsonParser struct

Recursive-descent JSON parser.

Use parseJson for one-shot parsing; the struct is exposed mainly so the parser state (position, error message) can be inspected when needed.

The JsonValue data model lives in "std/text/json-value" and serialization in "std/text/json-serializer".

Constructors

ctor

Spice
public p JsonParser.ctor(const String& input)

Construct a JSON parser over the given input string

Parameters

Name Type Description
input const String& JSON text to parse

Methods

parse

Spice
public f<Result<JsonValue*>> JsonParser.parse()

Parse the input string into a JSON value tree

Returns: Result<JsonValue*> — Result holding the root JSON value, or an error if the input is malformed

Functions

parseJson

Spice
public f<Result<JsonValue*>> parseJson(const String& input)

Parse a JSON document.

On success returns the root JsonValue (heap-allocated; the caller owns it). On failure returns an error describing the first problem encountered.

Parameters

Name Type Description
input const String&

Returns: Result<JsonValue*>