In go the standard package encoding/json exposes json.Unmarshal function to parse JSON.
I have a JSON like this:
{
...
"tyo": {
"ping_only": true,
"addresses": [
//"155.133.245.25:27015-27050",
//"155.133.245.26:27015-27050",
//"155.133.245.27:27015-27050",
"45.121.186.20:27015-27016",
"45.121.186.21:27015-27016"
]
},
"vie": {
"addresses": [
"185.25.182.225:27015-27050",
"185.25.182.226:27015-27050"
]
},
...
}
When I use json.Unmarshal I got error:
Handler crashed with error invalid character '/' looking for beginning of value
Can someone tell me how to parse this?
Strict JSON specification, don't allow comments.
But exist not-official superset of JSON that permits comments (and more other cool things), like JSON5 or HJSON (human-json).
You can try with these Go libraries:
I wrote a simple json uncommenter in go that support line comment. use it before unmarshal.
// f is a raw io.Reader
newReader := jsonuncommenter.RemoveComment(f)
jsonParser := json.NewDecoder(newReader)
var s seeds
jsonParser.Decode(&s)
https://github.com/wuxiangzhou2010/jsonuncommenter
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With