json-sanitizer icon indicating copy to clipboard operation
json-sanitizer copied to clipboard

If I have a JS comment all content is destroyed

Open ghost opened this issue 5 years ago • 3 comments

I have been looking for a few days how to heal my JSON files, until I saw that this library existed, I was doing some tests to see how it worked, and well I was quite scared to see that if I had a JS-style comment like this // Hello, I am a comment everything after it disappears, is that normal behavior?

For example my input json

[
    {
        "id": {
            "key": "value",
            "key": "value",
            "key": "value",
            "key": "value",		
			//Ey what's up
        },		
            "key": "value",
            "key": "value",
            "key": "value",
            "key": "value",
    },


... More keys below....

Output json:

[
    {
        "id": {
            "key": "value",
            "key": "value",
            "key": "value",
            "key": "value",
        }
    }
]

Everything below the comment disappears.

Edit: I am using the last version, 1.2.1

ghost avatar Jun 17 '20 11:06 ghost

I would suggest preprocessing your JSON to remove the comments and then use the JSON sanitizer. I believe your comments are illegal and we’re stripping out comments aggressively apparently.

Maybe Mike has more to add...

-- Jim Manico @Manicode

On Jun 17, 2020, at 7:09 AM, Adrian Lagartera [email protected] wrote:

 I have been looking for a few days how to heal my JSON files, until I saw that this library existed, I was doing some tests to see how it worked, and well I was quite scared to see that if I had a JS-style comment like this // Hello, I am a comment everything after it disappears, is that normal behavior?

For example my input json

[ { "id": { "key": "value", "key": "value", "key": "value", "key": "value", //Ey what's up }, "key": "value", "key": "value", "key": "value", "key": "value", },

... More keys below.... Output json:

[ { "id": { "key": "value", "key": "value", "key": "value", "key": "value", } } ] Everything below the comment disappears.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.

jmanico avatar Jun 17 '20 13:06 jmanico

I would suggest preprocessing your JSON to remove the comments and then use the JSON sanitizer. I believe your comments are illegal and we’re stripping out comments aggressively apparently. Maybe Mike has more to add... -- Jim Manico @manicode On Jun 17, 2020, at 7:09 AM, Adrian Lagartera @.***> wrote:  I have been looking for a few days how to heal my JSON files, until I saw that this library existed, I was doing some tests to see how it worked, and well I was quite scared to see that if I had a JS-style comment like this // Hello, I am a comment everything after it disappears, is that normal behavior? For example my input json [ { "id": { "key": "value", "key": "value", "key": "value", "key": "value", //Ey what's up }, "key": "value", "key": "value", "key": "value", "key": "value", }, ... More keys below.... Output json: [ { "id": { "key": "value", "key": "value", "key": "value", "key": "value", } } ] Everything below the comment disappears. — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.

As a solution it works for me, although it would be good to comment on it in my company so that it can be applied correctly. I will wait for Mike to comment if it is a bug, since according to what I saw in the documentation, it is normal to delete the comments, but I did not know that so aggressively.

Thank you very much for your comment.

ghost avatar Jun 17 '20 13:06 ghost

bump @mikesamuel

jmanico avatar Sep 21 '21 21:09 jmanico