Class JSON5KeyValuesMedia

java.lang.Object
io.jstach.ezkv.json5.JSON5KeyValuesMedia
All Implemented Interfaces:
KeyValuesMedia, KeyValuesServiceProvider, KeyValuesServiceProvider.KeyValuesMediaFinder

public final class JSON5KeyValuesMedia extends Object implements KeyValuesMedia
Parses JSON5 to KeyValues. The parser() can also be used for strict JSON as JSON5 is a true superset.

The constants in this class are important and describe parameters that can be set on the KeyValuesResource.

JSON is not flat and is more of a tree where as EZKV KeyValues are and only support string values. Thus the parser flattens the JSON based on some heuristics. JSON objects are easy to flatten but JSON arrays need special handling.

Here is an example of the default flattening:
	{
		"a": {
			"b": [1, 2.0, {"c": 3}],
			"d": "value"
		}
	}
Here is the corresponding key values (notice duplicates):
a.b=1
a.b=2.0
a.b.c=3
a.d=value

Because EZKV supports duplicates and order matters the data is not lost but this might be confusing. Another option is to generate array indices in the keys.

Assume we load a resource with the previous JSON like:

_load_a=classpath:/a.json5?_param_json5_arraykey=array

We will get flattened key values that look like:
a.b[0]=1
a.b[1]=2.0
a.b[2].c=3
a.d=value
Because both formats may not be what you want you might want to use a filter to clean up the results.

This module does have a service loader registration. If you do not wish to use the Service Loader you can add an instance of this class to KeyValuesSystem.Builder.

See Also:
API Note
This is not included with the core ezkv module because JSON5 is still evolving and likely to keep changing.