# JsonData

An immutable value in the JSON data model: what a JSON, YAML or TOML document means, independent of its syntax.

Class 

`OfficeIMO.Json`

**Namespace**

`OfficeIMO.Json`

**Assembly**

`OfficeIMO.Core`

**Source revision**

`ba882f6b0d07` with working tree changes

**Source**

[JsonData.cs:130](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Core/Json/JsonData.cs#L130)

**Modifiers**

sealed

An immutable value in the JSON data model: what a JSON, YAML or TOML document means, independent of its syntax. Each value can carry the one-based line and column it came from and the source node, so findings about it point back into the original file. [JsonSchema](/api/core/officeimo-json-jsonschema/) validates it; the YAML and TOML document models convert to it.

## Inheritance

- object
- JsonData

## Remarks

Numbers keep their exact decimal value at any precision, so 0.1, multipleOf and numbers beyond decimal or double range compare exactly; only infinities and NaN are inexact. Objects keep their properties in source order; a repeated name keeps its first position and its last value. Values nest at most 1024 levels deep.

## Usage

Explore 20 API references to this type

This type appears in these public API surfaces even when no hand-authored example is attached directly to the page.

### Returned or exposed by 12

- Method [JsonData.CreateArray](/api/core/officeimo-json-jsondata/#method-createarray-collections-generic-ienumerable-officeimo-json-jsondata-officeimo-json-jsondatalocation)
- Method [JsonData.CreateBoolean](/api/core/officeimo-json-jsondata/#method-createboolean-boolean-officeimo-json-jsondatalocation)
- Method [JsonData.CreateNull](/api/core/officeimo-json-jsondata/#method-createnull-officeimo-json-jsondatalocation)
- Method [JsonData.CreateNumber](/api/core/officeimo-json-jsondata/#method-createnumber-double)
- Method [JsonData.CreateObject](/api/core/officeimo-json-jsondata/#method-createobject-collections-generic-ienumerable-system-collections-generic-keyvaluepair-system-string-officeimo-json-jsondata-officeimo-json-jsondatalocation)
- Method [JsonData.CreateString](/api/core/officeimo-json-jsondata/#method-createstring-string-officeimo-json-jsondatalocation)
- Method [JsonData.Parse](/api/core/officeimo-json-jsondata/#method-parse-string)
- Method [JsonData.ParseNumber](/api/core/officeimo-json-jsondata/#method-parsenumber-string-officeimo-json-jsondatalocation)
- Property [JsonData.Items](/api/core/officeimo-json-jsondata/#property-items)
- Property [JsonData.Properties](/api/core/officeimo-json-jsondata/#property-properties)
- Property [JsonSchema.Root](/api/core/officeimo-json-jsonschema/#property-root)
- Property [JsonSchemaOptions.ReferenceResolver](/api/core/officeimo-json-jsonschemaoptions/#property-referenceresolver)

### Accepted by parameters 8

- Method [JsonData.CreateArray](/api/core/officeimo-json-jsondata/#method-createarray-collections-generic-ienumerable-officeimo-json-jsondata-officeimo-json-jsondatalocation) parameter `items`
- Method [JsonData.CreateObject](/api/core/officeimo-json-jsondata/#method-createobject-collections-generic-ienumerable-system-collections-generic-keyvaluepair-system-string-officeimo-json-jsondata-officeimo-json-jsondatalocation) parameter `properties`
- Method [JsonData.DeepEquals](/api/core/officeimo-json-jsondata/#method-deepequals-officeimo-json-jsondata-officeimo-json-jsondata) parameter `left`
- Method [JsonData.DeepEquals](/api/core/officeimo-json-jsondata/#method-deepequals-officeimo-json-jsondata-officeimo-json-jsondata) parameter `right`
- Method [JsonData.TryGetProperty](/api/core/officeimo-json-jsondata/#method-trygetproperty-string-officeimo-json-jsondata) parameter `value`
- Method [JsonSchema.IsValid](/api/core/officeimo-json-jsonschema/#method-isvalid-officeimo-json-jsondata) parameter `instance`
- Method [JsonSchema.Load](/api/core/officeimo-json-jsonschema/#method-load-officeimo-json-jsondata-officeimo-json-jsonschemaoptions) parameter `schema`
- Method [JsonSchema.Validate](/api/core/officeimo-json-jsonschema/#method-validate-officeimo-json-jsondata) parameter `instance`

Filter members 

Show inherited

## Methods

`public static JsonData CreateArray(IEnumerable<JsonData> items, JsonDataLocation location = default)` [#](#method-createarray-collections-generic-ienumerable-officeimo-json-jsondata-officeimo-json-jsondatalocation)

[JsonData.cs:183](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Core/Json/JsonData.cs#L183)

Creates an array from its items.

Parameters

**items System.Collections.Generic.IEnumerable<OfficeIMO.Json.JsonData> required**

**location OfficeIMO.Json.JsonDataLocation = default optional**

Returns

`JsonData`

Exceptions

- `ArgumentNullException` – items or one of its items is null.
- `ArgumentException` – The value would nest deeper than 1024 levels.

`public static JsonData CreateBoolean(bool value, JsonDataLocation location = default)` [#](#method-createboolean-boolean-officeimo-json-jsondatalocation)

[JsonData.cs:133](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Core/Json/JsonData.cs#L133)

Creates a boolean.

Parameters

**value bool required**

**location OfficeIMO.Json.JsonDataLocation = default optional**

Returns

`JsonData`

`public static JsonData CreateNull(JsonDataLocation location = default)` [#](#method-createnull-officeimo-json-jsondatalocation)

[JsonData.cs:130](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Core/Json/JsonData.cs#L130)

Creates the null value.

Parameters

**location OfficeIMO.Json.JsonDataLocation = default optional**

Returns

`JsonData`

CreateNumber 6 overloads

`public static JsonData CreateNumber(decimal value)` [#](#method-createnumber-decimal)

[JsonData.cs:141](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Core/Json/JsonData.cs#L141)

Creates an exact number.

Parameters

**value decimal required**

Returns

`JsonData`

`public static JsonData CreateNumber(decimal value, JsonDataLocation location)` [#](#method-createnumber-decimal-officeimo-json-jsondatalocation)

[JsonData.cs:145](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Core/Json/JsonData.cs#L145)

Creates an exact number with its source location.

Parameters

**value decimal required**

**location OfficeIMO.Json.JsonDataLocation required**

Returns

`JsonData`

`public static JsonData CreateNumber(long value)` [#](#method-createnumber-int64)

[JsonData.cs:150](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Core/Json/JsonData.cs#L150)

Creates an integer.

Parameters

**value long required**

Returns

`JsonData`

`public static JsonData CreateNumber(long value, JsonDataLocation location)` [#](#method-createnumber-int64-officeimo-json-jsondatalocation)

[JsonData.cs:153](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Core/Json/JsonData.cs#L153)

Creates an integer with its source location.

Parameters

**value long required**

**location OfficeIMO.Json.JsonDataLocation required**

Returns

`JsonData`

`public static JsonData CreateNumber(double value)` [#](#method-createnumber-double)

[JsonData.cs:159](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Core/Json/JsonData.cs#L159)

Creates a binary floating-point number. Finite values are kept as the exact decimal of their shortest round-trip form, so 0.1 stays 0.1; infinities and NaN, which JSON cannot write, are kept as inexact numbers.

Parameters

**value double required**

Returns

`JsonData`

`public static JsonData CreateNumber(double value, JsonDataLocation location)` [#](#method-createnumber-double-officeimo-json-jsondatalocation)

[JsonData.cs:163](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Core/Json/JsonData.cs#L163)

Creates a binary floating-point number with its source location; see [JsonData.CreateNumber](/api/core/officeimo-json-jsondata/).

Parameters

**value double required**

**location OfficeIMO.Json.JsonDataLocation required**

Returns

`JsonData`

`public static JsonData CreateObject(IEnumerable<KeyValuePair<string, JsonData>> properties, JsonDataLocation location = default)` [#](#method-createobject-collections-generic-ienumerable-system-collections-generic-keyvaluepair-system-string-officeimo-json-jsondata-officeimo-json-jsondatalocation)

[JsonData.cs:195](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Core/Json/JsonData.cs#L195)

Creates an object from its properties. A repeated name keeps its first position and its last value.

Parameters

**properties System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, OfficeIMO.Json.JsonData>> required**

**location OfficeIMO.Json.JsonDataLocation = default optional**

Returns

`JsonData`

Exceptions

- `ArgumentNullException` – properties, a name or a value is null.
- `ArgumentException` – The value would nest deeper than 1024 levels.

`public static JsonData CreateString(string value, JsonDataLocation location = default)` [#](#method-createstring-string-officeimo-json-jsondatalocation)

[JsonData.cs:138](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Core/Json/JsonData.cs#L138)

Creates a string.

Parameters

**value string required**

**location OfficeIMO.Json.JsonDataLocation = default optional**

Returns

`JsonData`

Exceptions

- `ArgumentNullException` – value is null.

`public static bool DeepEquals(JsonData? left, JsonData? right)` [#](#method-deepequals-officeimo-json-jsondata-officeimo-json-jsondata)

[JsonData.cs:262](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Core/Json/JsonData.cs#L262)

Returns whether two values are equal in the JSON data model: numbers by value, objects regardless of property order.

Parameters

**left OfficeIMO.Json.JsonData? required**

**right OfficeIMO.Json.JsonData? required**

Returns

`bool`

`public bool GetBoolean()` [#](#method-getboolean)

[JsonData.cs:222](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Core/Json/JsonData.cs#L222)

Gets a boolean's value.

Returns

`bool`

Exceptions

- `InvalidOperationException` – The value is not a boolean.

`public double GetDouble()` [#](#method-getdouble)

[JsonData.cs:230](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Core/Json/JsonData.cs#L230)

Gets a number as a double.

Returns

`double`

Exceptions

- `InvalidOperationException` – The value is not a number.

`public string GetString()` [#](#method-getstring)

[JsonData.cs:226](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Core/Json/JsonData.cs#L226)

Gets a string's value.

Returns

`string`

Exceptions

- `InvalidOperationException` – The value is not a string.

`public static JsonData Parse(string json)` [#](#method-parse-string)

[JsonData.cs:216](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Core/Json/JsonData.cs#L216)

Parses JSON text (RFC 8259), recording the line and column of every value.

Parameters

**json string required**

Returns

`JsonData`

Exceptions

- `ArgumentNullException` – json is null.
- `FormatException` – The text is not JSON, or nests deeper than 512 levels.

`public static JsonData ParseNumber(string text, JsonDataLocation location = default)` [#](#method-parsenumber-string-officeimo-json-jsondatalocation)

[JsonData.cs:172](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Core/Json/JsonData.cs#L172)

Creates a number from number text such as -1.5e3, keeping its exact value at any precision.

Parameters

**text string required**

**location OfficeIMO.Json.JsonDataLocation = default optional**

Returns

`JsonData`

Exceptions

- `ArgumentNullException` – text is null.
- `FormatException` – text is not a number.

`public override string ToString()` [#](#method-tostring)

[JsonData.cs:248](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Core/Json/JsonData.cs#L248)

Writes the value as compact JSON. Infinite and NaN numbers, which JSON cannot hold, are written as strings.

Returns

`string`

`public bool TryGetDecimal(out decimal value)` [#](#method-trygetdecimal-decimal)

[JsonData.cs:234](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Core/Json/JsonData.cs#L234)

Gets a number as an exact decimal; returns false for non-numbers and numbers a decimal cannot hold exactly.

Parameters

**value decimal required**

Returns

`bool`

`public bool TryGetProperty(string name, out JsonData value)` [#](#method-trygetproperty-string-officeimo-json-jsondata)

[JsonData.cs:240](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Core/Json/JsonData.cs#L240)

Gets an object's property by name.

Parameters

**name string required**

**value OfficeIMO.Json.JsonData required**

Returns

`bool`

## Inherited Methods

`public virtual bool Equals(object? obj)` [#](#method-equals-object)

Inherited from object

Parameters

**obj object? required**

Returns

`bool`

`public virtual int GetHashCode()` [#](#method-gethashcode)

Inherited from object

Returns

`int`

`public Type GetType()` [#](#method-gettype)

Inherited from object

Returns

`Type`

## Properties

`public JsonDataKind Kind { get; }` [#](#property-kind)

[JsonData.cs:106](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Core/Json/JsonData.cs#L106)

Gets the kind of value.

`public int Line { get; }` [#](#property-line)

[JsonData.cs:109](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Core/Json/JsonData.cs#L109)

Gets the one-based line the value starts on, or 0 when it has no source position.

`public int Column { get; }` [#](#property-column)

[JsonData.cs:112](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Core/Json/JsonData.cs#L112)

Gets the one-based column the value starts at, or 0 when it has no source position.

`public object? Source { get; }` [#](#property-source)

[JsonData.cs:115](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Core/Json/JsonData.cs#L115)

Gets the node the value was converted from, such as a YamlNode or TomlNode, or null.

`public JsonDataLocation Location { get; }` [#](#property-location)

[JsonData.cs:118](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Core/Json/JsonData.cs#L118)

Gets where the value came from.

`public bool IsInteger { get; }` [#](#property-isinteger)

[JsonData.cs:121](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Core/Json/JsonData.cs#L121)

Gets whether the value is a number with no fractional part, such as 3 or 3.0.

`public IReadOnlyList<JsonData> Items { get; }` [#](#property-items)

[JsonData.cs:124](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Core/Json/JsonData.cs#L124)

Gets the items of an array, or an empty list for other kinds.

`public IReadOnlyList<KeyValuePair<string, JsonData>> Properties { get; }` [#](#property-properties)

[JsonData.cs:127](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Core/Json/JsonData.cs#L127)

Gets the properties of an object in source order, or an empty list for other kinds.

<!-- PowerForge markdown artifact sha256:0DD3B125440B7B472AF9F391EAF44574A9A4DCD11D03F78F19F2B1618621E9D8 -->
