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_NAMESALLOW_TRAILING_COMMAALLOW_SINGLE_QUOTESALLOW_BACKSLASH_ESCAPING_ANY_CHARACTERALLOW_NON_NUMERIC_NUMBERSALLOW_JAVA_COMMENTSALLOW_LEADING_DECIMAL_POINT_FOR_NUMBERSit 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_NAMESfeature✅ Both supported with the
ALLOW_TRAILING_COMMAfeature✅ Supported with the
ALLOW_SINGLE_QUOTESfeature✅ Both of these appear to be supported by Jackson's
ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTERfeature, though the meaning or purpose of escaping here may differ subtly. DYOR.✅ Supported with the
ALLOW_NON_NUMERIC_NUMBERSfeature✅ Supported with the
ALLOW_JAVA_COMMENTSfeature.Partially Supported Features
The following JSON5 feature is partially supported by Jackson:
✅ Leading decimal points are supported with the
ALLOW_LEADING_DECIMAL_POINT_FOR_NUMBERSfeature.⛔️ 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: