Open-EO / openeo-test-suite

Test suite for validation of openEO back-ends against the openEO API specification
Apache License 2.0
0 stars 2 forks source link

Parse process examples in JSON5 format #2

Closed soxofaan closed 11 months ago

soxofaan commented 1 year ago

the process examples to use in the "individual process testing" are written as JSON5: https://github.com/Open-EO/openeo-processes/tree/add-tests/tests

I already found a couple of options to read JSON5:

I have no idea yet on which one to bet at the moment

soxofaan commented 1 year ago

interestingly, the json module from python stdlib does already support these JSON5 NaN and Infinity constructs properly:

>>> import json
>>> dump = '{"x": NaN, "y": Infinity, "z": -Infinity, "n": null}'
>>> for k, v in json.loads(dump).items():
...    print(k, repr(v), type(v))
x nan <class 'float'>
y inf <class 'float'>
z -inf <class 'float'>
n None <class 'NoneType'>

so a good solution for full JSON5 support is not that urgent or blocking at the moment

m-mohr commented 1 year ago

There are also comments added into the mix and I'm not sure whether Python's default json supports that.

soxofaan commented 1 year ago

nope, no support for other JSON5 features like comments, unquoted keys, single quotes, trailing coma

m-mohr commented 1 year ago

It really only uses comments, all other features I'm trying not to use. If it's much simpler to implement I could also use a "$comment" property as in JSON schema.

soxofaan commented 1 year ago

Stripping commas before json parsing will also be pretty easy to do DIY-style (regex oneliner) without the need for full fledged JSON5 library.

m-mohr commented 1 year ago

You mean comments, not commas, right? But yes indeed. A simple regex should be able to cater for removing comments and then it could go into the native Python JSON module.

soxofaan commented 1 year ago

You mean comments, not commas, right?

Indeed.

but now that you mention it: DIY-stripping trailing comma's shouldn't be that hard either

m-mohr commented 1 year ago

Yes, but I'll try to ensure that we only need to strip comments and handle NaN/Infinity. Otherwise, I'll stick to pure JSON for now.

m-mohr commented 11 months ago

I felt like writing code around the json module was not worth it right now, I just used json-five for now.