Trivial.Json 3.0.0

Includes writable JSON DOM and lots of JSON converters.

Install-Package Trivial.Json -Version 3.0.0
dotnet add package Trivial.Json --version 3.0.0
<PackageReference Include="Trivial.Json" Version="3.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Trivial.Json --version 3.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Includes writable JSON DOM and lots of useful JSON converters.

Note: This library/package is also a part of Trivial so no need to install this if you have already installed that.

Add following namespace to your code file to use.

using Trivial.Text;

Writable JSON DOM

You can create a writable JSON DOM including JSON object JsonObject and JSON array JsonArray.

var json = new JsonObject
{
    { "prop-a", 1234 },
    { "prop-b", "opq" },
    { "prop-c", true },
    { "prop-d", new JsonArray { 5678, "rst" } }
};

And you can write to an instance of System.Text.Json.Utf8JsonWriter by WriteTo member method or get the JSON format string by ToString member method.

JSON converters

Includes a lot of useful JSON converters so that you can use System.Text.Json.Serialization.JsonConvertAttribute attribute to use for member properties of the model.

Following are date time related.

  • JsonJavaScriptTicksConverter
  • JsonJavaScriptTicksConverter.NullableConverter
  • JsonJavaScriptTicksConverter.FallbackConverter
  • JsonJavaScriptTicksConverter.FallbackNullableConverter
  • JsonUnixTimestampConverter
  • JsonUnixTimestampConverter.NullableConverter
  • JsonUnixTimestampConverter.FallbackConverter
  • JsonUnixTimestampConverter.FallbackNullableConverter

Following are number related.

  • JsonNumberConverter
  • JsonNumberConverter.NumberStringConverter
  • JsonNumberConverter.StrictConverter

Following are string collection related.

  • JsonStringListConverter
  • JsonStringListConverter.WhiteSpaceSeparatedConverter
  • JsonStringListConverter.CommaSeparatedConverter
  • JsonStringListConverter.SemicolonSeparatedConverter
  • JsonStringListConverter.VerticalBarSeparatedConverter

Following are JsonObject and JsonArray related.

  • JsonObjectConverter

For example.

public class Model
{
    [JsonConverter(typeof(JsonNumberConverter))
    public int Number { get; set; }

    [JsonPropertyName("creation")]
    [JsonConverter(typeof(JsonJavaScriptTicksConverter))
    public DateTime CreationTime { get; set; }

    [JsonConverter(typeof(JsonObjectConverter)]
    public JsonObject Properties { get; set; }
}

Now you can deserialize following JSON.

{
    "number": "1234",
    "creation": 1577628663614,
    "properties": {
        "items": [ 5, 6, 7, "a", "b", "c" ]
        "b": true
    }
}

Includes writable JSON DOM and lots of useful JSON converters.

Note: This library/package is also a part of Trivial so no need to install this if you have already installed that.

Add following namespace to your code file to use.

using Trivial.Text;

Writable JSON DOM

You can create a writable JSON DOM including JSON object JsonObject and JSON array JsonArray.

var json = new JsonObject
{
    { "prop-a", 1234 },
    { "prop-b", "opq" },
    { "prop-c", true },
    { "prop-d", new JsonArray { 5678, "rst" } }
};

And you can write to an instance of System.Text.Json.Utf8JsonWriter by WriteTo member method or get the JSON format string by ToString member method.

JSON converters

Includes a lot of useful JSON converters so that you can use System.Text.Json.Serialization.JsonConvertAttribute attribute to use for member properties of the model.

Following are date time related.

  • JsonJavaScriptTicksConverter
  • JsonJavaScriptTicksConverter.NullableConverter
  • JsonJavaScriptTicksConverter.FallbackConverter
  • JsonJavaScriptTicksConverter.FallbackNullableConverter
  • JsonUnixTimestampConverter
  • JsonUnixTimestampConverter.NullableConverter
  • JsonUnixTimestampConverter.FallbackConverter
  • JsonUnixTimestampConverter.FallbackNullableConverter

Following are number related.

  • JsonNumberConverter
  • JsonNumberConverter.NumberStringConverter
  • JsonNumberConverter.StrictConverter

Following are string collection related.

  • JsonStringListConverter
  • JsonStringListConverter.WhiteSpaceSeparatedConverter
  • JsonStringListConverter.CommaSeparatedConverter
  • JsonStringListConverter.SemicolonSeparatedConverter
  • JsonStringListConverter.VerticalBarSeparatedConverter

Following are JsonObject and JsonArray related.

  • JsonObjectConverter

For example.

public class Model
{
    [JsonConverter(typeof(JsonNumberConverter))
    public int Number { get; set; }

    [JsonPropertyName("creation")]
    [JsonConverter(typeof(JsonJavaScriptTicksConverter))
    public DateTime CreationTime { get; set; }

    [JsonConverter(typeof(JsonObjectConverter)]
    public JsonObject Properties { get; set; }
}

Now you can deserialize following JSON.

{
    "number": "1234",
    "creation": 1577628663614,
    "properties": {
        "items": [ 5, 6, 7, "a", "b", "c" ]
        "b": true
    }
}

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
3.0.0 96 5/12/2020