JSON for Humans.
JSON is great. Until you miss that trailing comma... or want to use comments. What about multiline strings? JSONH provides a much more elegant way to write JSON that's designed for humans rather than machines.
Since JSONH is compatible with JSON, any JSONH syntax can be represented with equivalent JSON.
JsonhCs is a parser implementation of JSONH v1 for C# .NET.
{
// use #, // or /**/ comments
// quotes are optional
keys: without quotes,
// commas are optional
isn\'t: {
that: cool? # yes
}
// use multiline strings
haiku: '''
Let me die in spring
beneath the cherry blossoms
while the moon is full.
'''
// compatible with JSON5
key: 0xDEADCAFE
// or use JSON
"old school": 1337
}
Everything you need is contained within JsonhReader
:
string Jsonh = """
{
this is: awesome
}
""";
string Element = JsonhCs.JsonhReader.ParseElement<string>(Jsonh).Value!;
If using NativeAOT, you will need to use the JsonNode
APIs:
public class Player {
public required string Name { get; set; }
public required int Health { get; set; }
}
[JsonSourceGenerationOptions]
[JsonSerializable(typeof(Player))]
internal partial class PlayerContext : JsonSerializerContext {
}
string PlayerJsonh = """
Name: John Doe
Health: 9_999_999
""";
Player PlayerObject = JsonhCs.JsonhReader.ParseNode(PlayerJsonh).Value
.Deserialize(PlayerContext.Default.Player)!;