We'd like to parse JSON5 documents in the JVM, but the JSON5-specific libraries available on GitHub all appear to have very low support. As parsers are often magnets for security vulnerabilities, we'd prefer not to use a parser that isn't already being widely used and scrutinised by the community.
This got us to wondering: Can the optional features of the Jackson JSON parser be used to parse JSON5?
tl;dr
By enabling the following optional Jackson parser features:
ALLOW_UNQUOTED_FIELD_NAMES
ALLOW_TRAILING_COMMA
ALLOW_SINGLE_QUOTES
ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER
ALLOW_NON_NUMERIC_NUMBERS
ALLOW_JAVA_COMMENTS
ALLOW_LEADING_DECIMAL_POINT_FOR_NUMBERS
it seems possible to support all of JSON5's headline features except for:
Detail
Jackson has a number of optional features which can be enabled on a parser to make it more lenient in the way it parses.
Supported Features
Comparing these parser options to the headline features of JSON5, we find that the following are supported:
✅ Supported with the
ALLOW_UNQUOTED_FIELD_NAMES
feature✅ Both supported with the
ALLOW_TRAILING_COMMA
feature✅ Supported with the
ALLOW_SINGLE_QUOTES
feature✅ Both of these appear to be supported by Jackson's
ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER
feature, though the meaning or purpose of escaping here may differ subtly. DYOR.✅ Supported with the
ALLOW_NON_NUMERIC_NUMBERS
feature✅ Supported with the
ALLOW_JAVA_COMMENTS
feature.Partially Supported Features
The following JSON5 feature is partially supported by Jackson:
✅ Leading decimal points are supported with the
ALLOW_LEADING_DECIMAL_POINT_FOR_NUMBERS
feature.⛔️ Jackson doesn't appear to have support for trailing decimal points.
Unsupported Features
There doesn't currently (mid-2021) appear to be any way to configure Jackson to permit the following JSON5 features: