import json
let
small_json = """
{ "test": 1.3,
"key2": true,
}"""
jobj = parseJson(small_json)
Because of the , (comma) after true I would expect getting an exception from parseJson but I won't
I believe this a bug in parsing JSON? Or did I miss anything?
-- Manfred
I have no exception. It compiles well.
Result of echo jobj is:
{"test":1.3,"key2":true}
Update your sources.
Why exception? It is correct json.
Golang, nodejs, python3 do the same too. What's wrong?
I don't believe you.
Take this JSON document:
}
and parse it with go or anything else.
Sorry, Go json.Unmarshal does not parse the same.
I think it is possible in other golang json libs.
I checked nodejs 5.3.0, python3. They parse that json well
According to the spec, this is not a valid JSON (i.e. there can't be a trailing comma inside an object): http://www.json.org/
However, I think it's not a bug to not reject it.
However, I think it's not a bug to not reject it.
Of course, from a practical point of view it doesn't much matter if there is a trailing comma or not. But it validates the spec. Therefore I would say it is a bug to accept it.
It's a bug. In a JSON parser I wrote in OCaml, I had an optional strict argument to the function call which defaulted to true which would cause trailing commas to be accepted if false.
Trailing commas are very common in the wild for obvious reasons but strictly speaking they're invalid JSON.