pub enum Json {
    Null,
    Bool(bool),
    Number(Number),
    String(String),
    Array(Vec<Value, Global>),
    Object(Map<String, Value>),
}
Expand description

Represents any valid JSON value.

See the serde_json::value module documentation for usage examples.

Variants

Null

Represents a JSON null value.

let v = json!(null);

Bool(bool)

Represents a JSON boolean.

let v = json!(true);

Number(Number)

Represents a JSON number, whether integer or floating point.

let v = json!(12.5);

String(String)

Represents a JSON string.

let v = json!("a string");

Array(Vec<Value, Global>)

Represents a JSON array.

let v = json!(["an", "array"]);

Object(Map<String, Value>)

Represents a JSON object.

By default the map is backed by a BTreeMap. Enable the preserve_order feature of serde_json to use IndexMap instead, which preserves entries in the order they are inserted into the map. In particular, this allows JSON data to be deserialized into a Value and serialized to a string while retaining the order of map keys in the input.

let v = json!({ "an": "object" });

Trait Implementations

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Layout

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference’s “Type Layout” chapter for details on type layout guarantees.

Size: 32 bytes

Size for each variant:

  • Null: 0 bytes
  • Bool: 1 byte
  • Number: 23 bytes
  • String: 31 bytes
  • Array: 31 bytes
  • Object: 31 bytes