Skip to content

Mode for replacing comments with spaces and leaving original whitespace in #17

@stirante

Description

@stirante

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.
stirante@c4ec348

I understand that not many people might want this behavior which is why I propose to add it as a separate setting/mode.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions