JsonData
OfficeIMO.Json
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 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
- Method JsonData.CreateBoolean
- Method JsonData.CreateNull
- Method JsonData.CreateNumber
- Method JsonData.CreateObject
- Method JsonData.CreateString
- Method JsonData.Parse
- Method JsonData.ParseNumber
- Property JsonData.Items
- Property JsonData.Properties
- Property JsonSchema.Root
- Property JsonSchemaOptions.ReferenceResolver
Accepted by parameters 8
- Method JsonData.CreateArray
- Method JsonData.CreateObject
- Method JsonData.DeepEquals
- Method JsonData.DeepEquals
- Method JsonData.TryGetProperty
- Method JsonSchema.IsValid
- Method JsonSchema.Load
- Method JsonSchema.Validate
Methods
public static JsonData CreateArray(IEnumerable<JsonData> items, JsonDataLocation location = default) #Creates an array from its items.
Parameters
- items System.Collections.Generic.IEnumerable<OfficeIMO.Json.JsonData>
- location OfficeIMO.Json.JsonDataLocation = default
Returns
JsonDataExceptions
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) #Creates a boolean.
Parameters
- value bool
- location OfficeIMO.Json.JsonDataLocation = default
Returns
JsonDatapublic static JsonData CreateNull(JsonDataLocation location = default) #Creates the null value.
Parameters
- location OfficeIMO.Json.JsonDataLocation = default
Returns
JsonDatapublic static JsonData CreateNumber(decimal value) #Creates an exact number.
Parameters
- value decimal
Returns
JsonDatapublic static JsonData CreateNumber(decimal value, JsonDataLocation location) #Creates an exact number with its source location.
Parameters
- value decimal
- location OfficeIMO.Json.JsonDataLocation
Returns
JsonDatapublic static JsonData CreateNumber(long value) #Creates an integer.
Parameters
- value long
Returns
JsonDatapublic static JsonData CreateNumber(long value, JsonDataLocation location) #Creates an integer with its source location.
Parameters
- value long
- location OfficeIMO.Json.JsonDataLocation
Returns
JsonDatapublic static JsonData CreateNumber(double value) #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
Returns
JsonDatapublic static JsonData CreateNumber(double value, JsonDataLocation location) #Creates a binary floating-point number with its source location; see JsonData.CreateNumber.
Parameters
- value double
- location OfficeIMO.Json.JsonDataLocation
Returns
JsonDatapublic static JsonData CreateObject(IEnumerable<KeyValuePair<string, JsonData>> properties, JsonDataLocation location = default) #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>>
- location OfficeIMO.Json.JsonDataLocation = default
Returns
JsonDataExceptions
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) #Creates a string.
Parameters
- value string
- location OfficeIMO.Json.JsonDataLocation = default
Returns
JsonDataExceptions
ArgumentNullException– value is null.
public static bool DeepEquals(JsonData? left, JsonData? right) #Returns whether two values are equal in the JSON data model: numbers by value, objects regardless of property order.
Parameters
- left OfficeIMO.Json.JsonData?
- right OfficeIMO.Json.JsonData?
Returns
boolpublic bool GetBoolean() #Gets a boolean's value.
Returns
boolExceptions
InvalidOperationException– The value is not a boolean.
public double GetDouble() #Gets a number as a double.
Returns
doubleExceptions
InvalidOperationException– The value is not a number.
public string GetString() #Gets a string's value.
Returns
stringExceptions
InvalidOperationException– The value is not a string.
public static JsonData Parse(string json) #Parses JSON text (RFC 8259), recording the line and column of every value.
Parameters
- json string
Returns
JsonDataExceptions
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) #Creates a number from number text such as -1.5e3, keeping its exact value at any precision.
Parameters
- text string
- location OfficeIMO.Json.JsonDataLocation = default
Returns
JsonDataExceptions
ArgumentNullException– text is null.FormatException– text is not a number.
public override string ToString() #Writes the value as compact JSON. Infinite and NaN numbers, which JSON cannot hold, are written as strings.
Returns
stringpublic bool TryGetDecimal(out decimal value) #Gets a number as an exact decimal; returns false for non-numbers and numbers a decimal cannot hold exactly.
Parameters
- value decimal
Returns
boolpublic bool TryGetProperty(string name, out JsonData value) #Gets an object's property by name.
Parameters
- name string
- value OfficeIMO.Json.JsonData
Returns
boolInherited Methods
Properties
public int Line { get; } #Gets the one-based line the value starts on, or 0 when it has no source position.
public int Column { get; } #Gets the one-based column the value starts at, or 0 when it has no source position.
public object? Source { get; } #Gets the node the value was converted from, such as a YamlNode or TomlNode, or null.
public bool IsInteger { get; } #Gets whether the value is a number with no fractional part, such as 3 or 3.0.
public IReadOnlyList<JsonData> Items { get; } #Gets the items of an array, or an empty list for other kinds.
public IReadOnlyList<KeyValuePair<string, JsonData>> Properties { get; } #Gets the properties of an object in source order, or an empty list for other kinds.