Skip to main content
Log in

Mojo struct

JSONParser

struct JSONParser[mut: Bool, //, origin: Origin[mut]]

A parser for JSON text.

This struct provides methods to parse JSON text into structured JSONValue objects. It works directly on the UTF-8 bytes of the source string.

Parameters

  • mut (Bool): Whether the parser is mutable.
  • origin (Origin[mut]): The origin of the parser's memory.

Implemented traits

AnyType, UnknownDestructibility

Methods

__init__

__init__(out self, span: StringSlice[origin])

Initializes a new JSON parser with the given string slice.

Args:

  • span (StringSlice[origin]): The string slice to parse.

parse_value

parse_value(mut self) -> JSONValue[origin]

Parses a JSON value at the current position.

Returns:

The parsed JSON value.

Raises:

Error: If the JSON is invalid.