Skip to main content

Search OfficeIMO

Enter a topic, API type, or PowerShell command.

Documentation Search all OfficeIMO/
Class

JsonData

OfficeIMO.Json

Namespace
OfficeIMO.Json
Assembly
OfficeIMO.Core
Source revision
ba882f6b0d07 with working tree changes
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 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.

Accepted by parameters 8

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> 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) #

Creates a boolean.

Parameters

value bool required
location OfficeIMO.Json.JsonDataLocation = default optional

Returns

JsonData
public static JsonData CreateNull(JsonDataLocation location = default) #

Creates the null value.

Parameters

location OfficeIMO.Json.JsonDataLocation = default optional

Returns

JsonData
CreateNumber 6 overloads
public static JsonData CreateNumber(decimal value) #

Creates an exact number.

Parameters

value decimal required

Returns

JsonData
public static JsonData CreateNumber(decimal value, JsonDataLocation location) #

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) #

Creates an integer.

Parameters

value long required

Returns

JsonData
public static JsonData CreateNumber(long value, JsonDataLocation location) #

Creates an integer with its source location.

Parameters

value long required
location OfficeIMO.Json.JsonDataLocation required

Returns

JsonData
public 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 required

Returns

JsonData
public static JsonData CreateNumber(double value, JsonDataLocation location) #

Creates a binary floating-point number with its source location; see JsonData.CreateNumber.

Parameters

value double required
location OfficeIMO.Json.JsonDataLocation required

Returns

JsonData
public 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>> 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) #

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) #

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() #

Gets a boolean's value.

Returns

bool

Exceptions

  • InvalidOperationException – The value is not a boolean.
public double GetDouble() #

Gets a number as a double.

Returns

double

Exceptions

  • InvalidOperationException – The value is not a number.
public string GetString() #

Gets a string's value.

Returns

string

Exceptions

  • 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 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) #

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() #

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) #

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) #

Gets an object's property by name.

Parameters

name string required
value OfficeIMO.Json.JsonData required

Returns

bool

Properties

public JsonDataKind Kind { get; } #

Gets the kind of value.

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 JsonDataLocation Location { get; } #

Gets where the value came from.

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.