Hjson 4.0.0-rc.1

This is a prerelease version of Hjson.
dotnet add package Hjson --version 4.0.0-rc.1
                    
NuGet\Install-Package Hjson -Version 4.0.0-rc.1
                    
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="Hjson" Version="4.0.0-rc.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Hjson" Version="4.0.0-rc.1" />
                    
Directory.Packages.props
<PackageReference Include="Hjson" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Hjson --version 4.0.0-rc.1
                    
#r "nuget: Hjson, 4.0.0-rc.1"
                    
#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.
#:package Hjson@4.0.0-rc.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Hjson&version=4.0.0-rc.1&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Hjson&version=4.0.0-rc.1&prerelease
                    
Install as a Cake Tool

hjson-cs

nuget version License

Hjson, a user interface for JSON

Hjson Intro

JSON is easy for humans to read and write... in theory. In practice JSON gives us plenty of opportunities to make mistakes without even realizing it.

Hjson is a syntax extension to JSON. It's NOT a proposal to replace JSON or to incorporate it into the JSON spec itself. It's intended to be used like a user interface for humans, to read and edit before passing the JSON data to the machine.

{
  # specify rate in requests/second (because comments are helpful!)
  rate: 1000

  // prefer c-style comments?
  /* feeling old fashioned? */

  # did you notice that rate doesn't need quotes?
  hey: look ma, no quotes for strings either!

  # best of all
  notice: []
  anything: ?

  # yes, commas are optional!
}

Supported frameworks/runtimes include .NET Core, .NET 4.x & Mono.

This library includes two readers/writers that fully conform to the respective specification:

  • JSON
  • Hjson

The C# implementation of Hjson is based on System.Json. For other platforms see hjson.github.io.

Install from nuget

Install-Package Hjson

Usage

You can either

  • use this libary directly
  • or just convert Hjson to JSON and use it with your favorite JSON library.

Convert

// convert Hjson to JSON
var jsonString = HjsonValue.Load(filePath).ToString();

// convert JSON to Hjson
var hjsonString = JsonValue.Load("test.json").ToString(Stringify.Hjson);

Read

var jsonObject = HjsonValue.Load(filePath).Qo();

HjsonValue.Load() will accept both Hjson and JSON. You can use JsonValue.Load() to accept JSON input only.

Object sample

var jsonObject = HjsonValue.Parse("{\"name\":\"hugo\",\"age\":5}").Qo();
string name = jsonObject.Qs("name");
int age = jsonObject.Qi("age");
// you may prefer to get any value as string
string age2 = jsonObject.Qstr("age");

// or iterate over the members
foreach (var item in jsonObject)
{
  Console.WriteLine("{0}: {1}", item.Key, item.Value);
}

Array sample

var jsonArray = HjsonValue.Parse("[\"hugo\",5]").Qa();
string first = jsonArray[0];

// or iterate over the members
foreach (var item in jsonArray)
  Console.WriteLine(item.ToValue());

Nested sample

var nested = HjsonValue.Parse("{\"partner\":{\"name\":\"John\",\"age\":23}}").Qo();
string name = nested.Qo("partner").Qs("name", "default");
int age = nested.Qo("partner").Qi("age", 77);
string gender = nested.Qo("partner").Qs("gender", "unknown");

Create

var jsonObject = new JsonObject
{
  { "name", "John" },
  { "age", 23 },
};
// -> { "name": "John", "age", 23 }

JsonArray jsonArray = new JsonArray()
{
  "John",
  23,
};
// -> [ "John", 23 ]

Modify

jsonObject["name"] = "Hugo";
jsonObject.Remove("age");

Write

HjsonValue.Save(jsonObject, "file.hjson"); // as Hjson
HjsonValue.Save(jsonObject, "file.json"); // as JSON

ToString()

jsonObject.ToString(Stringify.Hjson); // Hjson output
jsonObject.ToString(Stringify.Formatted); // formatted JSON output
jsonObject.ToString(Stringify.Plain); // plain JSON output, default
jsonObject.ToString(); // plain

Also see the sample.

API

See api.md.

From the Commandline

A commandline tool to convert from/to Hjson is available in the cli folder.

For other tools see hjson.github.io.

Source/Projects

Solutions in the root folder target .NET Core.

Solutions for .NET 4.x can be found in the legacy folder.

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

    • No dependencies.

NuGet packages (12)

Showing the top 5 NuGet packages that depend on Hjson:

Package Downloads
SerApi

Package Description

Ser.Engine

Package Description

daVinci-wpf

Package Description

TomLabs.Shadowgem

Library that provides extension and helper methods of all kinds.

Ser.Engine.Rest

Package Description

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on Hjson:

Repository Stars
anoyetta/ACT.Hojoring
Advanced Combat Tracker の FFXIV向けプラグインです。トリガ、TTSの拡張、HUDの拡張など。
Version Downloads Last Updated
4.0.0-rc.1 47 3/17/2026
3.0.0 117,734 7/18/2017
2.1.3 2,555 1/18/2017
2.1.2 2,571 11/16/2016
2.1.1 1,887 11/16/2016
2.1.0 2,411 9/22/2016
2.0.2 2,210 8/19/2016
2.0.0 3,516 8/2/2016
1.14.4 4,298 4/29/2016
1.14.3 2,743 2/4/2016
1.14.2 2,752 8/21/2015
1.14.0 2,469 5/6/2015
1.11.3 2,464 4/16/2015
1.11.2 2,299 3/18/2015
1.11.1 2,499 1/29/2015
1.11.0 2,512 1/12/2015
1.9.0 2,481 1/9/2015
1.8.0 2,392 1/8/2015
1.7.0 2,565 1/3/2015
Loading failed