Show / Hide Table of Contents

Class JsonValue

Represents a JSON value.

Inheritance
System.Object
JsonValue
Implements
System.IEquatable<JsonValue>
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
Namespace: Manatee.Json
Assembly: Manatee.Json.dll
Syntax
public class JsonValue : IEquatable<JsonValue>
Remarks

A value can consist of a string, a numerical value, a boolean (true or false), a null placeholder, a JSON array of values, or a nested JSON object.

Constructors

| Improve this Doc View Source

JsonValue()

Creates a null JsonValue.

Declaration
public JsonValue()
| Improve this Doc View Source

JsonValue(JsonArray)

Creates a JsonValue from a JSON array.

Declaration
public JsonValue(JsonArray a)
Parameters
Type Name Description
JsonArray a
| Improve this Doc View Source

JsonValue(JsonObject)

Creates a JsonValue from a JSON object.

Declaration
public JsonValue(JsonObject o)
Parameters
Type Name Description
JsonObject o
| Improve this Doc View Source

JsonValue(JsonValue)

Creates a copy of a JsonValue.

Declaration
public JsonValue(JsonValue other)
Parameters
Type Name Description
JsonValue other
| Improve this Doc View Source

JsonValue(Boolean)

Creates a JsonValue from a boolean.

Declaration
public JsonValue(bool b)
Parameters
Type Name Description
System.Boolean b
| Improve this Doc View Source

JsonValue(Double)

Creates a JsonValue from a numeric value.

Declaration
public JsonValue(double n)
Parameters
Type Name Description
System.Double n
| Improve this Doc View Source

JsonValue(String)

Creates a JsonValue from a string.

Declaration
public JsonValue(string s)
Parameters
Type Name Description
System.String s

Fields

| Improve this Doc View Source

Null

Globally defined null-valued JSON value.

Declaration
public static readonly JsonValue Null
Field Value
Type Description
JsonValue
Remarks

When adding values to a JsonObject or JsonArray, nulls will automatically be converted into this field.

Properties

| Improve this Doc View Source

Array

Accesses the JsonValue as a JSON array.

Declaration
public JsonArray Array { get; }
Property Value
Type Description
JsonArray
Exceptions
Type Condition
JsonValueIncorrectTypeException

Thrown when this JsonValue does not contain a Json array.

| Improve this Doc View Source

Boolean

Accesses the JsonValue as a boolean.

Declaration
public bool Boolean { get; }
Property Value
Type Description
System.Boolean
Exceptions
Type Condition
JsonValueIncorrectTypeException

Thrown when this JsonValue does not contain a boolean.

| Improve this Doc View Source

Number

Accesses the JsonValue as a numeric value.

Declaration
public double Number { get; }
Property Value
Type Description
System.Double
Exceptions
Type Condition
JsonValueIncorrectTypeException

Thrown when this JsonValue does not contain a numeric value.

| Improve this Doc View Source

Object

Accesses the JsonValue as a JSON object.

Declaration
public JsonObject Object { get; }
Property Value
Type Description
JsonObject
Exceptions
Type Condition
JsonValueIncorrectTypeException

Thrown when this JsonValue does not contain a Json object.

| Improve this Doc View Source

String

Accesses the JsonValue as a string.

Declaration
public string String { get; }
Property Value
Type Description
System.String
Remarks

Setting the value as a string will automatically change the JsonValue's type and discard the old data.

Exceptions
Type Condition
JsonValueIncorrectTypeException

Thrown when this JsonValue does not contain a string.

| Improve this Doc View Source

Type

Gets the value type of the existing data.

Declaration
public JsonValueType Type { get; }
Property Value
Type Description
JsonValueType

Methods

| Improve this Doc View Source

Equals(Nullable<JsonValue>)

Indicates whether the current object is equal to another object of the same type.

Declaration
public bool Equals(JsonValue? other)
Parameters
Type Name Description
System.Nullable<JsonValue> other

An object to compare with this object.

Returns
Type Description
System.Boolean

true if the current object is equal to the other parameter; otherwise, false.

| Improve this Doc View Source

Equals(Nullable<Object>)

Determines whether the specified System.Object is equal to the current System.Object.

Declaration
public override bool Equals(object? obj)
Parameters
Type Name Description
System.Nullable<System.Object> obj

The System.Object to compare with the current System.Object.

Returns
Type Description
System.Boolean

true if the specified System.Object is equal to the current System.Object; otherwise, false.

| Improve this Doc View Source

GetHashCode()

Serves as a hash function for a particular type.

Declaration
public override int GetHashCode()
Returns
Type Description
System.Int32

A hash code for the current System.Object.

Overrides
System.Object.GetHashCode()
| Improve this Doc View Source

GetIndentedString(Int32)

Creates a string representation of the JSON data.

Declaration
public string GetIndentedString(int indentLevel = 0)
Parameters
Type Name Description
System.Int32 indentLevel

The indention level for the value.

Returns
Type Description
System.String

A string.

| Improve this Doc View Source

Parse(TextReader)

Parses data from a System.IO.StreamReader containing a JSON value.

Declaration
public static JsonValue Parse(TextReader stream)
Parameters
Type Name Description
System.IO.TextReader stream

the System.IO.StreamReader to parse.

Returns
Type Description
JsonValue

The JSON value represented by the System.String.

Exceptions
Type Condition
System.ArgumentNullException

Thrown if stream is null.

System.ArgumentException

Thrown if stream is at the end.

JsonSyntaxException

Thrown if stream contains invalid JSON syntax.

| Improve this Doc View Source

Parse(String)

Parses a System.String containing a JSON value.

Declaration
public static JsonValue Parse(string source)
Parameters
Type Name Description
System.String source

the System.String to parse.

Returns
Type Description
JsonValue

The JSON value represented by the System.String.

Exceptions
Type Condition
System.ArgumentNullException

Thrown if source is null.

System.ArgumentException

Thrown if source is empty or whitespace.

JsonSyntaxException

Thrown if source contains invalid JSON syntax.

| Improve this Doc View Source

ParseAsync(TextReader)

Parses data from a System.IO.StreamReader containing a JSON value.

Declaration
public static Task<JsonValue> ParseAsync(TextReader stream)
Parameters
Type Name Description
System.IO.TextReader stream

the System.IO.StreamReader to parse.

Returns
Type Description
System.Threading.Tasks.Task<JsonValue>

The JSON value represented by the System.String.

Exceptions
Type Condition
System.ArgumentNullException

Thrown if stream is null.

System.ArgumentException

Thrown if stream is at the end.

JsonSyntaxException

Thrown if stream contains invalid JSON syntax.

| Improve this Doc View Source

ToString()

Creates a string that represents this JsonValue.

Declaration
public override string ToString()
Returns
Type Description
System.String

A string representation of this JsonValue.

Overrides
System.Object.ToString()
Remarks

Passing the returned string back into the parser will result in a copy of this JsonValue.

Operators

| Improve this Doc View Source

Equality(Nullable<JsonValue>, Nullable<JsonValue>)

Performs an equality comparison between two JsonValues.

Declaration
public static bool operator ==(JsonValue? a, JsonValue? b)
Parameters
Type Name Description
System.Nullable<JsonValue> a

A JsonValue.

System.Nullable<JsonValue> b

A JsonValue.

Returns
Type Description
System.Boolean

true if the values are equal; otherwise, false.

| Improve this Doc View Source

Implicit(Boolean to JsonValue)

Implicitly converts a System.Boolean into a JsonValue.

Declaration
public static implicit operator JsonValue(bool b)
Parameters
Type Name Description
System.Boolean b

A System.Boolean.

Returns
Type Description
JsonValue

A JsonValue that represents the System.Boolean.

Remarks

This is useful when creating an initialized JsonObject or JsonArray.

Examples
JsonObject obj = new JsonObject{
{&quot;stringData&quot;, &quot;string&quot;},
{&quot;numberData&quot;, 10.6},
{&quot;boolData&quot;, true},
{&quot;arrayData&quot;, new JsonArray{false, &quot;Array String&quot;, JsonValue.Null, 8e-4}},
{&quot;objectData&quot;, new JsonObject{
{&quot;stringData2&quot;, &quot;another string&quot;},
{&quot;moreBoolData&quot;, false}}}};
| Improve this Doc View Source

Implicit(Double to JsonValue)

Implicitly converts a System.Double into a JsonValue.

Declaration
public static implicit operator JsonValue(double n)
Parameters
Type Name Description
System.Double n

A System.Double.

Returns
Type Description
JsonValue

A JsonValue that represents the System.Double.

Remarks

This is useful when creating an initialized JsonObject or JsonArray.

Examples
JsonObject obj = new JsonObject{
{&quot;stringData&quot;, &quot;string&quot;},
{&quot;numberData&quot;, 10.6},
{&quot;boolData&quot;, true},
{&quot;arrayData&quot;, new JsonArray{false, &quot;Array String&quot;, JsonValue.Null, 8e-4}},
{&quot;objectData&quot;, new JsonObject{
{&quot;stringData2&quot;, &quot;another string&quot;},
{&quot;moreBoolData&quot;, false}}}};
| Improve this Doc View Source

Implicit(Nullable<JsonArray> to JsonValue)

Implicitly converts a JsonArray into a JsonValue.

Declaration
public static implicit operator JsonValue(JsonArray? a)
Parameters
Type Name Description
System.Nullable<JsonArray> a

A JSON array.

Returns
Type Description
JsonValue

A JsonValue that represents the JsonArray.

Remarks

This is useful when creating an initialized JsonObject or JsonArray.

Examples
JsonObject obj = new JsonObject{
{&quot;stringData&quot;, &quot;string&quot;},
{&quot;numberData&quot;, 10.6},
{&quot;boolData&quot;, true},
{&quot;arrayData&quot;, new JsonArray{false, &quot;Array String&quot;, JsonValue.Null, 8e-4}},
{&quot;objectData&quot;, new JsonObject{
{&quot;stringData2&quot;, &quot;another string&quot;},
{&quot;moreBoolData&quot;, false}}}};
| Improve this Doc View Source

Implicit(Nullable<JsonObject> to JsonValue)

Implicitly converts a JsonObject into a JsonValue.

Declaration
public static implicit operator JsonValue(JsonObject? o)
Parameters
Type Name Description
System.Nullable<JsonObject> o

A JSON object.

Returns
Type Description
JsonValue

A JsonValue that represents the JsonObject.

Remarks

This is useful when creating an initialized JsonObject or JsonArray.

Examples
JsonObject obj = new JsonObject{
{&quot;stringData&quot;, &quot;string&quot;},
{&quot;numberData&quot;, 10.6},
{&quot;boolData&quot;, true},
{&quot;arrayData&quot;, new JsonArray{false, &quot;Array String&quot;, JsonValue.Null, 8e-4}},
{&quot;objectData&quot;, new JsonObject{
{&quot;stringData2&quot;, &quot;another string&quot;},
{&quot;moreBoolData&quot;, false}}}};
| Improve this Doc View Source

Implicit(Nullable<String> to JsonValue)

Implicitly converts a System.String into a JsonValue.

Declaration
public static implicit operator JsonValue(string? s)
Parameters
Type Name Description
System.Nullable<System.String> s

A System.String.

Returns
Type Description
JsonValue

A JsonValue that represents the System.String.

Remarks

This is useful when creating an initialized JsonObject or JsonArray.

Examples
JsonObject obj = new JsonObject{
{&quot;stringData&quot;, &quot;string&quot;},
{&quot;numberData&quot;, 10.6},
{&quot;boolData&quot;, true},
{&quot;arrayData&quot;, new JsonArray{false, &quot;Array String&quot;, JsonValue.Null, 8e-4}},
{&quot;objectData&quot;, new JsonObject{
{&quot;stringData2&quot;, &quot;another string&quot;},
{&quot;moreBoolData&quot;, false}}}};
| Improve this Doc View Source

Inequality(Nullable<JsonValue>, Nullable<JsonValue>)

Performs an inverted equality comparison between two JsonValues.

Declaration
public static bool operator !=(JsonValue? a, JsonValue? b)
Parameters
Type Name Description
System.Nullable<JsonValue> a

A JsonValue.

System.Nullable<JsonValue> b

A JsonValue.

Returns
Type Description
System.Boolean

false if the values are equal; otherwise, true.

Implements

System.IEquatable<T>

Extension Methods

XmlExtensions.ToXElement(JsonValue, String)
JsonTransformer.Transform(JsonValue, JsonValue)
  • Improve this Doc
  • View Source
Back to top Generated by DocFX