Skip to main content
Log in

Mojo struct

JSONValue

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

Represents a JSON value of any type (null, boolean, number, string, array, or object).

Parameters

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

Aliases

  • KIND_NULL = __init__[__mlir_type.!pop.int_literal](0):
  • KIND_BOOL = __init__[__mlir_type.!pop.int_literal](1):
  • KIND_NUMBER = __init__[__mlir_type.!pop.int_literal](2):
  • KIND_STRING = __init__[__mlir_type.!pop.int_literal](3):
  • KIND_ARRAY = __init__[__mlir_type.!pop.int_literal](4):
  • KIND_OBJECT = __init__[__mlir_type.!pop.int_literal](5):

Implemented traits

AnyType, Copyable, Movable, Representable, Stringable, UnknownDestructibility, Writable

Methods

__init__

__init__(out self)

Initializes a new JSON value as null.

@implicit __init__(out self, v: _NoneType)

Initializes a new JSON value as null.

Args:

  • v (_NoneType): The null value.

@implicit __init__(out self, v: Bool)

Initializes a new JSON value as a boolean.

Args:

  • v (Bool): The boolean value.

@implicit __init__(out self, s: SIMD[float64, 1])

Initializes a new JSON value as a floating-point number.

Args:

  • s (SIMD[float64, 1]): The floating-point value.

@implicit __init__(out self, s: String)

Initializes a new JSON value as a string.

Args:

  • s (String): The string value.

@implicit __init__(out self, a: List[JSONValue[origin]])

Initializes a new JSON value as an array.

Args:

  • a (List[JSONValue[origin]]): The list of JSON values.

@implicit __init__(out self, o: Dict[String, JSONValue[origin]])

Initializes a new JSON value as an object.

Args:

  • o (Dict[String, JSONValue[origin]]): The dictionary of string keys to JSON values.

@implicit __init__(out self, o: JSONDict[origin])

Initializes a new JSON value as an object.

Args:

  • o (JSONDict[origin]): The JSON dictionary.

__copyinit__

__copyinit__(out self, other: Self)

Initializes a new JSON value as a copy of another.

Args:

  • other (Self): The JSON value to copy.

__moveinit__

__moveinit__(out self, owned existing: Self)

Initializes a new JSON value by moving another.

Args:

  • existing (Self): The JSON value to move.

write_to

write_to[W: Writer, //](self, mut writer: W)

Writes a string representation of the JSONValue to the given writer.

Outputs the JSONValue in its JSON string representation according to the JSON standard (RFC 8259).

Parameters:

  • W (Writer): The type of the writer, conforming to the Writer trait.

Args:

  • writer (W): The writer instance to output the representation to.

__str__

__str__(self) -> String

Returns a string representation of the JSON value.

Returns:

A string containing the JSON representation.

__repr__

__repr__(self) -> String

Returns a string representation of the JSON value.

Returns:

A string containing the JSON representation.