mouse07410 / asn1c

The ASN.1 Compiler
http://lionet.info/asn1c/
BSD 2-Clause "Simplified" License
93 stars 70 forks source link

jer: Minified JSON option #160

Closed v0-e closed 8 months ago

v0-e commented 8 months ago

This proposes the addition of a new ATS_JER_MINIFIED to produce more lightweight JSONs without whitespaces. The output of the current default ATS_JER remains unchanged (pretty-printing).

The JER standard (X.697) does not define either a pretty or a minified JSON, stating only that JER-compliant JSONs can have any number of whitespaces between tokens. The examples that it provides are based on a pretty format, so I think we should preserve the ATS_JER for the pretty encoding. Nevertheless, a more compact JSON is both smaller and faster to decode, so depending on the application it can be preferable to be used over the pretty format.

Let me know if you would like to change the name of the ATS(s).

This PR is an alternative to #108.

Example with ATS_JER:

{
    "int1": 851,
    "intopt1": 12412,
    "seqofch": [
        {
            "int1": 61
        },
        {
            "seqofbs": [
                "0203",
                "030405",
                "04050607",
                "0506070809"
            ]
        }
    ],
    "bs": "02040608",
    "os": "020406080A",
    "seqofint": [
        9509,
        919,
        99
    ],
    "ch": {
        "seqofbool": [
            false,
            false,
            false
        ]
    },
    "seqofnull": [
        null,
        null,
        null
    ],
    "bool1": true,
    "null1": null,
    "enumerated1": "rejected",
    "roi": "8.9.10.11",
    "bmps": "",
    "utf": "15u0001ABC",
    "setofps": [
        "stringA",
        "another\"string"
    ],
    "setofnull": [
    ],
    "gt": "19821106210629.456",
    "r": "-INF",
    "seqA": {
        "int1": 0,
        "bool1": true,
        "enumerated1": "tryagain"
    }
}

Example with ATS_JER_MINIFIED:

{"int1":851,"intopt1":12412,"seqofch":[{"int1":61},{"seqofbs":["0203","030405","04050607","0506070809"]}],"bs":"02040608","os":"020406080A","seqofint":[9509,919,99],"ch":{"seqofbool":[false,false,false]},"seqofnull":[null,null,null],"bool1":true,"null1":null,"enumerated1":"rejected","roi":"8.9.10.11","bmps":"","utf":"15u0001ABC","setofps":["stringA","another\"string"],"setofnull":[],"gt":"19821106210629.456","r":"-INF","seqA":{"int1":0,"bool1":true,"enumerated1":"tryagain"}}
mouse07410 commented 8 months ago

This proposes the addition of a new ATS_JER_MINIFIED to produce more lightweight JSONs without whitespaces

I would strongly object to replacing the current JSON with "minified". But adding "minified as an option seems reasonable.

The output of the current default ATS_JER remains unchanged (pretty-printing).

Which is what makes this PR viable.

a more compact JSON is both smaller and faster to decode, so depending on the application it can be preferable to be used over the pretty format.

I'm not sure I see a use case. On the other hand - since it doesn't seem to hurt anything, and somebody seems to benefit from it - why not.

Let me know if you would like to change the name of the ATS(s).

We can do that later, if objections come in. Otherwise, ATS_JER_MINIFIED looks as good as any.

Thanks!

mouse07410 commented 8 months ago

Please feel free to add tests for this. A separate PR for tests is fine.