jsonc
jsonc copied to clipboard
Mode for replacing comments with spaces and leaving original whitespace in
While working with this library I noticed an issue when loading user-created JSON. The offsets of the errors in JSON is completely broken in case of syntax errors.
Example (from my memory)
Input JSON:
{
//this is a comment
"field": "value",
}
In this case, the translation will remove comment and all unneeded whitespace and will result in something like this (not actual output)
{"field":"value",}
When unmarshalling it, it will throw an error about trailing comma (actually about expecting a property, but it's caused by trailing comma) with offset of around 16. When applying this offset to the original JSON, the offset is completely wrong and the user cannot easily find it.
To fix it I left all whitespace in + replaced all comments with spaces in my fork of this library. https://github.com/stirante/jsonc/commit/c4ec34866fdd58b94c38db497febe30286f99e51
I understand that not many people might want this behavior which is why I propose to add it as a separate setting/mode.
Thanks for taking giving this library your time. I'll look into it. Right now I am stuck with another project so this might get delayed.
Thanks again.