Trivial.Json
3.6.0
See the version list below for details.
dotnet add package Trivial.Json --version 3.6.0
NuGet\Install-Package Trivial.Json -Version 3.6.0
<PackageReference Include="Trivial.Json" Version="3.6.0" />
paket add Trivial.Json --version 3.6.0
#r "nuget: Trivial.Json, 3.6.0"
// Install Trivial.Json as a Cake Addin #addin nuget:?package=Trivial.Json&version=3.6.0 // Install Trivial.Json as a Cake Tool #tool nuget:?package=Trivial.Json&version=3.6.0
Includes writable JSON DOM and lots of useful JSON converters.
Note: This library/package is also a part of Trivial so no need install this if you have already installed that.
Add following namespace to your code file to use.
using Trivial.Text;
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" } }
};
You can also get or set the property of JSON object as you want.
var num = json.GetInt32Value("prop-a"); // 1234
var numStr = json.GetStringValue("prop-a"); // "1234"
For scenarios of concurrency, you can enable thread-safe mode.
json.EnableThreadSafeMode();
At last, 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.
var jsonStr = json.ToString(IndentStyles.Compact);
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.
Converter | .NET type | JSON value kind (serialize/deserialize) | Additional JSON value kind (deserialize only) | Nullable |
---|---|---|---|---|
JsonJavaScriptTicksConverter |
DateTime |
JavaScript ticks number |
Date JSON string |
× |
JsonJavaScriptTicksConverter.NullableConverter |
DateTime? |
JavaScript ticks number |
Date JSON string |
√ |
JsonJavaScriptTicksConverter.FallbackConverter |
DateTime |
Date JSON string |
JavaScript ticks number |
× |
JsonJavaScriptTicksConverter.FallbackNullableConverter |
DateTime? |
Date JSON string |
JavaScript ticks number |
√ |
JsonUnixTimestampConverter |
DateTime |
Unix timestamp number |
Date JSON string |
× |
JsonUnixTimestampConverter.NullableConverter |
DateTime? |
Unix timestamp number |
Date JSON string |
√ |
JsonUnixTimestampConverter.FallbackConverter |
DateTime |
Date JSON string |
Unix timestamp number |
× |
JsonUnixTimestampConverter.FallbackNullableConverter |
DateTime? |
Date JSON string |
Unix timestamp number |
√ |
Following are number related.
Converter | .NET type | JSON value kind (serialize/deserialize) | Additional JSON value kind (deserialize only) | Nullable |
---|---|---|---|---|
JsonNumberConverter |
number types | number |
number string |
√ |
JsonNumberConverter.NumberStringConverter |
number types | number string |
number |
√ |
JsonNumberConverter.StrictConverter |
number types | number |
number string |
× |
Following are string collection related.
Converter | .NET type | JSON value kind | Nullable |
---|---|---|---|
JsonStringListConverter |
common class of IEnumerable<string> |
string or string[] |
√ |
JsonStringListConverter.WhiteSpaceSeparatedConverter |
common class of IEnumerable<string> |
string or string[] |
√ |
JsonStringListConverter.CommaSeparatedConverter |
common class of IEnumerable<string> |
string or string[] |
√ |
JsonStringListConverter.SemicolonSeparatedConverter |
common class of IEnumerable<string> |
string or string[] |
√ |
JsonStringListConverter.VerticalBarSeparatedConverter |
common class of IEnumerable<string> |
string or string[] |
√ |
Following are others.
Converter | .NET type | JSON value kind | Nullable |
---|---|---|---|
JsonObjectConverter |
JsonObject or JsonArray |
object or array |
√ |
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
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 is compatible. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETCoreApp 3.1
- No dependencies.
-
.NETStandard 2.0
- System.Text.Json (>= 5.0.0)
-
net5.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.