mholt / json-to-go

Translates JSON into a Go type in your browser instantly (original)
https://mholt.github.io/json-to-go/
MIT License
4.48k stars 473 forks source link

JSON.parse: expected property name or '}' at line 1 column 2 of the JSON data #125

Closed 3052 closed 5 months ago

3052 commented 5 months ago

input:

{
    "message": {
        "subject": "Meet for lunch?",
        "body": {
            "content": "The new cafeteria is open."
        },
        "toRecipients": [
            {
                "emailAddress": {
                    "address": "hello@world.com"
                }
            }
        ]
    }
}
3052 commented 5 months ago

ah, the problem is the "spaces" in the input are No-Break Space U+00A0. looks like that's invalid for both the JavaScript parser and Go parser:

panic: invalid character '\u00a0' looking for beginning of value

so maybe its my error. might be good to warn the user though if NBSP are found in the input

mholt commented 5 months ago

Ha, wow. I've never seen that happen before but if it happens repeatedly maybe I'll add a quick warning... (or I'd accept a PR) :+1: