hjson-cs
hjson-cs copied to clipboard
A new library.
Since hjson-cs has been abandoned, I created my own parser: HjsonSharp (MIT-license).
Aside from being actively maintained, it has a number of benefits over this existing library:
- Supports parsing HJSON, JSON5, JSONC and JSON
- Integrated with
System.Text.Json - Stream one
JsonTokenat a time without loading the entire document into memory - Customisable feature switches for each non-JSON feature (want HJSON with hexadecimal numbers?)
- Compatible with UTF-8, UTF-16, UTF-32 and ASCII encodings
- Parse incomplete values, such as
{"key": "val - Uses the
Resultpattern to avoid the overhead of exceptions - Supports escaped string newlines in single and double quoted strings, which were recently approved
Despite adding so many features, I think the source code is much more readable and structured than this library.
In terms of performance, the libraries are similar:
| Method | Mean | Error | StdDev | Gen0 | Gen1 | Gen2 | Allocated |
|---|---|---|---|---|---|---|---|
| LongStringHjsonCs | 11,135,676.0 ns | 25,272.15 ns | 21,103.39 ns | 1093.7500 | 1031.2500 | 734.3750 | 7828.64 KB |
| LongStringHjsonSharp | 19,753,082.7 ns | 71,314.79 ns | 66,707.90 ns | 375.0000 | 375.0000 | 375.0000 | 9956.86 KB |
| ShortIntegerHjsonCs | 3,952.6 ns | 18.41 ns | 15.37 ns | 0.4578 | - | - | 1.41 KB |
| ShortIntegerHjsonSharp | 615.7 ns | 3.08 ns | 2.88 ns | 0.3519 | - | - | 1.08 KB |
| PersonHjsonCs | 2,440.2 ns | 18.83 ns | 17.61 ns | 1.0376 | - | - | 3.19 KB |
| PersonHjsonSharp | 4,658.1 ns | 22.55 ns | 21.09 ns | 2.5177 | - | - | 7.73 KB |
LongString is a 1,000,000 character string, ShortInteger is a 5 digit number, and Person is a simple object with five properties.
I'm happy to fix bugs or add new HJSON features if the specification changes. In my opinion, HJSON is far superior to JSON5.
Cool! I'll add link and badges on https://hjson.github.io/.