JPoke 1.0.0

dotnet add package JPoke --version 1.0.0
NuGet\Install-Package JPoke -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="JPoke" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add JPoke --version 1.0.0
#r "nuget: JPoke, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install JPoke as a Cake Addin
#addin nuget:?package=JPoke&version=1.0.0

// Install JPoke as a Cake Tool
#tool nuget:?package=JPoke&version=1.0.0

JPoke

JPoke is a a simple library that allows construction or manipulation of JSON/YAML structured objects from the C# domain. For example:

var builder = JObjectBuilder.CreateEmpty();
builder.Set("settings[0].size",new {x=100,y=200});
builder.Copy("settings[0].size.x","config.initial_width");
Console.WriteLine(builder.ToJson());
{
  "config": {
	"initial_width": 100
  },
  "settings" : [ 
                  { 
                      "size": { 
                                  "x" : 100, 
                                  "y" : 200
                       }
                  
                ]
}

JPoke is able to construct intermediate nodes and elements as required.

Rationale

JPoke was written to support the VegaSharp library where the underlying Vega-Lite Json is too variable to allow simple mapping to C# structure equivalents and too deeply nested for dynamic objects to be useful.

Usage

Custom serialisation

JPoke does not support serialisation of custom types; however you can construct a JObjectBuilder from a serialised string and then use that as a value...

var jsonText = CustomSerializer.Deserialise(customObject);
var objectToBeInserted = JObjectBuilder.FromJson(jsonText);
builder.Set("complexNode",objectToBeInserted);


Construction

All object manipulation is done via a JObjectBuilder.

var builder = JObjectBuilder.CreateEmpty();
var builder = JObjectBuilder.FromJson(jsonString);
var builder = JObjectBuilder.FromObject(object); 

Writing

Values are set using "dotted" syntax to indicated structure and square brackets for array indices.

Values may be primitive types or structured objects. It is also possible set "serialised"

Examples:

var

builder.Set("settings[0].size",new {x=100,y=200});

Indexer syntax

[] [1] [+1] [-1]

Policies

ExtendArrays/NoExtend ArrayFillNull/ArrayFillEmpty/ArrayFillCopy/ArrayFillDefault (for primitives) OverwriteAllowed AutoConstruct

Conventions...

var builder = JObjectBuilder.FromJson();
var builder = JObjectBuilder.FromObject(object/JObjectBuilder/JsonNode)

var json = builder.ToJson(); //Serialize()
var object = builder.ToJsonNode();
var object = builder.Deserialize<T>();



Mutability

JObjectBuilder is mutable. All value objects/trees are cloned when setting nodes.

YAML

...to come

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

NuGet packages (1)

Showing the top 1 NuGet packages that depend on JPoke:

Package Downloads
VegaGenerator

Simple creation of VegaLite charts

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 126 3/3/2024

Initial release