Judo: Embeddable JSON and JSON5 Parser

Posted on 2025-02-14T19:36:00Z    #judo

Today, Railgun Labs is proud to announce Judo – a simple and secure JSON and JSON5 parser written in C99.

Choose Your Standard

Judo offers three JSON standards to choose from:

  • RFC 4627 - The original JSON standard, “discovered” by Douglas Crockford.
  • RFC 8259 - The latest JSON standard.
  • JSON5 - An unofficial extension of JSON, incorporating features from ECMAScript 5.1 (ES5).

The most notable difference between RFC 4627 and RFC 8259 is that, in the former, the root value must be an array or an object, whereas in the latter, the root value can be any valid JSON value.

Supported Extensions

Judo supports extensions for comments and trailing commas, which can be enabled for both RFC 4627 and RFC 8259. When both extensions are enabled, the parser becomes a JSONC parser. These features are already part of the JSON5 standard.

Why JSON5?

JSON5 is an extension of JSON syntax that incorporates features from ECMAScript 5.1 (ES5). Like standard JSON, JSON5 is valid JavaScript syntax.

JSON5 was selected over competing extensions because it extends JSON with features present in ES5, rather than inventing new syntax. As a result, it is more in line with what a next-generation JSON standard might look like. It also has a published specification, unlike various other JSON flavors.

You can learn more about JSON5 from its official website.

Lightweight and Robust

Judo’s scanner API consists of only three functions, all of which are idempotent. All errors are gracefully handled and returned to the caller.

Judo’s parser API is optional. It builds an in-memory tree representation of the JSON structure.

Both the Judo scanner and parser are non-recursive and thread-safe. Both can process null and non-null terminated UTF-8 encoded strings. They can both detect malformed UTF-8 sequences and problematic conditions not fully specified in the JSON specification, such as mismatched UTF-16 surrogate pairs.

MISRA C:2012 Compliance

The Judo scanner honors all Mandatory, Required, and Advisory rules defined in MISRA C:2012, including Rule 17.2, which requires functions to be non-recursive. As a result, Judo does not implement a recursive scanner or parser.

The optional Judo parser honors all MISRA rules except Advisory Rules 11.5 and 19.2. If strict conformance is required, then the parser interface can be disabled at configuration time.

You can view the full compliance table online.

Ultra Portable

Judo does not require an FPU or 64-bit integers. It only requires a few features from libc which are listed on the projects homepage.

Closing Thoughts

Judo introduces a secure and portable JSON and JSON5 parser, ideal for embedded systems.

The public source distribution is available here.