Class HjsonParser

All Implemented Interfaces:
HjsonMetaProvider, RecordReadable

public class HjsonParser extends ReaderParser implements HjsonMetaProvider, RecordReadable
Parses Hjson (Human JSON) text into POJO models.
Media types

Handles Content-Type types: application/hjson, application/hjson+json

Description

This parser handles all standard Hjson syntax as defined by the Hjson specification.

In addition to standard JSON, this parser handles the following:

  • # single-line comments (to end of line).
  • // single-line comments.
  • /* ... */ block comments.
  • Quoteless string values (text read to end of line, leading/trailing whitespace trimmed).
  • Multiline strings delimited by ''' (triple single-quote) with indentation stripping.
  • Optional commas — newlines may serve as member/element separators.
  • Trailing commas (ignored).
  • Unquoted keys.
  • Root-braceless objects (top-level content without wrapping {}).

Value type disambiguation: the parser identifies value types in this order: number → boolean → null → quoteless string. A value such as 5 times that starts like a number but contains non-numeric characters is treated as a quoteless string.

This parser handles the following input and returns the corresponding Java type:

  • Hjson/JSON objects ({...}) are converted to JsonMaps. Note: If a _type='xxx' attribute is specified on the object, an attempt is made to convert the object to an instance of the specified Java bean class.
  • Hjson/JSON arrays ([...]) are converted to JsonLists.
  • Quoted strings ("..." or '...') are converted to Strings.
  • Multiline strings ('''...''') are converted to Strings.
  • Quoteless strings are converted to Strings.
  • Numbers are converted to Integers, Longs, Floats, or Doubles depending on size and format.
  • true/false are converted to Booleans.
  • null returns null.
  • Input consisting of only whitespace or comments returns null.
Example input - readable mode:

{ name: Alice age: 30 }

Example input - compact mode:

{name:Alice,age:30}

Notes:
  • Root-braceless Hjson files (content without a wrapping {}) are supported on input, but HjsonSerializer always emits root braces by default. A parse-then-serialize round-trip of a root-braceless file will produce braced output.
  • This class is thread safe and reusable.
See Also: