JsonFlatten 1.0.4
dotnet add package JsonFlatten --version 1.0.4
NuGet\Install-Package JsonFlatten -Version 1.0.4
<PackageReference Include="JsonFlatten" Version="1.0.4" />
<PackageVersion Include="JsonFlatten" Version="1.0.4" />
<PackageReference Include="JsonFlatten" />
paket add JsonFlatten --version 1.0.4
#r "nuget: JsonFlatten, 1.0.4"
#:package JsonFlatten@1.0.4
#addin nuget:?package=JsonFlatten&version=1.0.4
#tool nuget:?package=JsonFlatten&version=1.0.4
JsonFlatten
Extension methods to flatten or unflatten a JSON.NET JObject to or from an IDictionary<string, object>.
This library is compatible with both .NET and .NET Framework.
Example
https://dotnetfiddle.net/jYghhm
This:
{
"$id": "https://example.com/arrays.schema.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"description": "A representation of a person, company, organization, or place",
"type": "object",
"properties": {
"fruits": {
"type": "array",
"items": {
"type": "string"
}
},
"vegetables": {
"type": "array",
"items": { "$ref": "#/definitions/veggie" }
}
},
"definitions": {
"veggie": {
"type": "object",
"required": [ "veggieName", "veggieLike" ],
"properties": {
"veggieName": {
"type": "string",
"description": "The name of the vegetable."
},
"veggieLike": {
"type": "boolean",
"description": "Do I like this vegetable?"
}
}
}
}
}
Becomes this:
{
"$id": "https://example.com/arrays.schema.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"description": "A representation of a person, company, organization, or place",
"type": "object",
"properties.fruits.type": "array",
"properties.fruits.items.type": "string",
"properties.vegetables.type": "array",
"properties.vegetables.items.$ref": "#/definitions/veggie",
"definitions.veggie.type": "object",
"definitions.veggie.required[0]": "veggieName",
"definitions.veggie.required[1]": "veggieLike",
"definitions.veggie.properties.veggieName.type": "string",
"definitions.veggie.properties.veggieName.description": "The name of the vegetable.",
"definitions.veggie.properties.veggieLike.type": "boolean",
"definitions.veggie.properties.veggieLike.description": "Do I like this vegetable?"
}
using System;
using System.Collections.Generic;
using JsonFlatten;
using Newtonsoft.Json.Linq;
public class Program
{
public static void Main()
{
var json = @"{ 'array': [ 1, 2, 3 ], 'boolean': true, 'null': null, 'number': 123, 'object': { 'a': 'b', 'c': 'd', 'e': 'f' }, 'date': '2014-01-01T23:28:56.782Z', 'string': 'Hello World', 'emptyString': '', 'emptyObject': {}, 'emptyArray': [] }";
JObject jObj = JObject.Parse(json);
// Flatten a JObject to a dictionary.
var flattened = jObj.Flatten();
// or Dictionary<string, object> flattened = new Dictionary<string, object>(jObj.Flatten());
// Retrieve and cast an item from the dictionary
var date = flattened.Get<DateTime>("date"); // 1/1/2014 11:28:56 PM
// Unflatten a dictionary to a JObject
JObject unflattened = flattened.Unflatten();
JToken.DeepEquals(jObj, unflattened); // True
// Update an entry
flattened.Set("date", date.AddDays(5));
// Try get logic for properties
flattened.TryGet<DateTime>("date", out var updatedDate); // updatedDate: 1/6/2014 11:28:56 PM
// Flatten a JObject and exclude any properties that are null or empty e.g. have the value null, "", {}, or []
var flattenedWithoutEmpty = jObj.Flatten(includeNullAndEmptyValues: false);
}
}
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp1.0 was computed. netcoreapp1.1 was computed. netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard1.1 is compatible. netstandard1.2 was computed. netstandard1.3 was computed. netstandard1.4 was computed. netstandard1.5 was computed. netstandard1.6 was computed. netstandard2.0 was computed. netstandard2.1 was computed. |
| .NET Framework | net45 was computed. net451 was computed. net452 was computed. net46 was computed. 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 | tizen30 was computed. tizen40 was computed. tizen60 was computed. |
| Universal Windows Platform | uap was computed. uap10.0 was computed. |
| Windows Phone | wpa81 was computed. |
| Windows Store | netcore was computed. netcore45 was computed. netcore451 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 1.1
- NETStandard.Library (>= 1.6.1)
- Newtonsoft.Json (>= 13.0.1)
NuGet packages (9)
Showing the top 5 NuGet packages that depend on JsonFlatten:
| Package | Downloads |
|---|---|
|
IglooSoftware.Sdk.EventSourcing
Igloo Event Sourcing SDK for services. |
|
|
Fathym
The Fathym reference architecture projects provide the foundation for building Fathym's dotnet applications. |
|
|
Cecrets
A tool for sharing sensitive data across your projects. |
|
|
LoopNet
Unofficial Loopring SDK in .NET 7 |
|
|
JsonataQueryBuilder
Generate jsonata Query. |
GitHub repositories
This package is not used by any popular GitHub repositories.