You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Uncaught SyntaxError: Expected 'a' instead of 'u' at line 4 column 14 of the JSON5 data. Still to read: "unction (data, state"
at JSON5.parse.error (node_modules/json5/lib/json5.js:56:25)
at JSON5.parse.next (node_modules/json5/lib/json5.js:72:17)
at JSON5.parse.word (node_modules/json5/lib/json5.js:366:17)
at JSON5.parse.value (node_modules/json5/lib/json5.js:493:56)
at JSON5.parse.object (node_modules/json5/lib/json5.js:459:35)
at JSON5.parse.value (node_modules/json5/lib/json5.js:482:20)
at JSON5.parse.object (node_modules/json5/lib/json5.js:459:35)
at JSON5.parse.value (node_modules/json5/lib/json5.js:482:20)
at Object.parse (node_modules/json5/lib/json5.js:508:18)
The problem is that this switch-case statement doesn't expect a function. In fact in the comments says
// Parse a JSON value. It could be an object, an array, a string, a number,// or a word.
Now, as far as I know that is a valid json value, I tested in chrome console, so, the parser should also accept functions as values for json properties.
Mmm it seems that's not a valid json but it is a valid js object.
I'm working in a browserify transform, so I have to parse some js code as a string. I don't know if your library is supposed to handle js objects or jsons, in fact I started using it because of native JSON.parse and JSON.stringify limitations. I guess I'll look for a regex for now.
If you think this use case is out of scope, just close this issue, if don't I'll wait for a solution.
Activity
jordanbtucker commentedon Oct 7, 2016
I think you're the first person to ask for support for functions. What is your use case for this?
Also, the result of the string you're trying to parse is not a valid JSON value. Just run the following code:
And you'll get:
{ "local": { "active": true }, "effects": {} }Note that the function is missing from the JSON result.
YerkoPalma commentedon Oct 7, 2016
Mmm it seems that's not a valid json but it is a valid js object.
I'm working in a browserify transform, so I have to parse some js code as a string. I don't know if your library is supposed to handle js objects or jsons, in fact I started using it because of native
JSON.parseandJSON.stringifylimitations. I guess I'll look for a regex for now.If you think this use case is out of scope, just close this issue, if don't I'll wait for a solution.
Thanks for your time anyway :)
jordanbtucker commentedon Oct 7, 2016
If you're looking to parse JavaScript, you should look into Esprima, Acorn, and UglifyJS.
Parsing functions is out of the scope of JSON5. Thanks.
crapthings commentedon Oct 21, 2019
i have same issue as @YerkoPalma
my string is like this
after parse each line will turn into an array item, but the nested kv pair include function that is not string
but i think you're right this is not a valid json, but any idea i can add JSON5 to solve this temporary ? then i might try using a lex analyzer