Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A new library. #12

Open
Joy-less opened this issue Jan 17, 2025 · 1 comment
Open

A new library. #12

Joy-less opened this issue Jan 17, 2025 · 1 comment

Comments

@Joy-less
Copy link

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 JsonToken at 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 Result pattern 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.

@trobro
Copy link
Member

trobro commented Jan 18, 2025

Cool! I'll add link and badges on https://hjson.github.io/.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants