esa-esdl/esdl-core

Invalid JSON in .zattrs file

Opened this issue · 1 comments

I have problems reading the new datacubes from the Julia API, because the attributes contain some invalid JSON, for example:

jovyan@ffd431271abc:~/.julia/packages/CMake/ZGawK/deps/downloads$ cat /home/jovyan/work/datacube/ESDCv2.0.0/esdc-8d-0.25deg-184x90x90-2.0.0.zarr/Rg/.zattrs
{
    "ID": 2,
    "_ARRAY_DIMENSIONS": [
        "time",
        "lat",
        "lon"
    ],
    "esa_cci_path": NaN,
    "long_name": "Downwelling shortwave radiation",
    "orig_version": "15.10.2017",
    "project_name": "BESS",
    "time_coverage_end": "2010-12-31",
    "time_coverage_resolution": "P8D",
    "time_coverage_start": "2000-03-01",
    "url": "http://environment.snu.ac.kr/bess_rad/"

This contains the entry NaN which should be converted to null according to JSON spec. I don't know if the error comes from the xarray, zarr or some other python package, but could we work around this issue by setting non-existing attributes in python to either None, which should be converted to null when encoding to JSON or to empty strings?

Here is the relevant section in the python module json.dump documentation https://docs.python.org/3/library/json.html:

If allow_nan is false (default: True), then it will be a ValueError to serialize out of range float values (nan, inf, -inf) in strict compliance of the JSON specification. If allow_nan is true, their JavaScript equivalents (NaN, Infinity, -Infinity) will be used.

So they do not adhere to JSON specs by default.