Comments (8)
What do you expect it to produce? Object
as you're using it refers to the native Object function, and functions aren't valid data types in JSON or JSON5.
from json5.
Actual the I'm trying to parse following message.
{
"status": 500,
"errors": [
{
"message": "{ ValidationError: { title: [ [Object] ] } }",
"stack": "Error: { ValidationError: { title: [ [Object] ] } }\n at Object.serverErrorOccurred [as handle] (/home/wunder/projects/Taskboard/config/500.js:27:34)\n at next (/home/wunder/projects/Taskboard/node_modules/sails/node_modules/express/node_modules/connect/lib/proto.js:185:17)\n at next (/home/wunder/projects/Taskboard/node_modules/sails/node_modules/express/node_modules/connect/lib/proto.js:187:11)\n at next (/home/wunder/projects/Taskboard/node_modules/sails/node_modules/express/node_modules/connect/lib/proto.js:187:11)\n at next (/home/wunder/projects/Taskboard/node_modules/sails/node_modules/express/node_modules/connect/lib/proto.js:187:11)\n at pass (/home/wunder/projects/Taskboard/node_modules/sails/node_modules/express/lib/router/index.js:107:24)\n at nextRoute (/home/wunder/projects/Taskboard/node_modules/sails/node_modules/express/lib/router/index.js:100:7)\n at callbacks (/home/wunder/projects/Taskboard/node_modules/sails/node_modules/express/lib/router/index.js:164:11)\n at /home/wunder/projects/Taskboard/node_modules/sails/lib/hooks/controllers/controller.create.js:31:20\n at /home/wunder/projects/Taskboard/node_modules/sails/node_modules/waterline/lib/waterline/query/dql.js:120:22"
}
]
}
And as you can see the problematic case is an string which i'm trying to parse. Basically this is a sails.js validation problem, but it would be nice if JSON5 handle this kind of cases. Maybe there should be optional method to make loose parse which handles cases like this.
My simple solution for this was var object = JSON5.parse(errorObject.message.replace("[ [Object] ]", "[]"));
from json5.
That's an interesting use case. I can see why you're asking, but I'm not sure what a good solution would be. I'm also not sure if JSON5 should solve this since it strays quite a bit from the purpose of being a data format that's easy to write by hand. Let's chew on this, and feedback from others welcome.
from json5.
If it's okay, I'm going to close this since the workaround is straightforward enough, and I'm not sure that it'd be right for JSON parsers to accept and parse [Object]
as []
or {}
. Thanks for raising, though!
from json5.
@tarlepp , I think it might be worth it to ask core team to change [ [Object] ]
to [ /*Object*/ ]
. This way json5 parser will parse it correctly.
from json5.
Yes, they already did that ( thanks to sails.js team ). Note that my proposal solutions was enough for me for that time the real solution was not available. Thanks anyway.
from json5.
Yes, they already did that ( thanks to sails.js team ).
We're talking about util.inspect() function in node.js core, right? It still produces [Object] in those cases.
Did sails.js return raw inspect output instead of javascript?
from json5.
there was a bug in sails.js core and in those cases returned value were converted to string.
from json5.
Related Issues (20)
- Module '"node_modules/json5/lib/index"' has no default export HOT 1
- Support Integers outside the range `[-(2**53)+1, (2**53)-1]` HOT 6
- SyntaxError when require()ing JSON5 file in Jest test HOT 1
- Prototype Pollution in JSON5 HOT 11
- json5 latest is now 1.0.2 on npmjs - intentional? HOT 3
- Support Template Literals using backticks? HOT 1
- Provide `exports` config in `packages.json`
- Multiline JSON doesn't multiline HOT 1
- add key property support ? HOT 1
- Add `comma-dangle` option HOT 7
- Online JSON5 Editor(Formatter) is misleading? HOT 2
- Use .substring() instead of the deprecated .substr()
- Cannot stringify "\u0000"
- transitive dependency 'minimist' needs to be updated by rebuilding HOT 1
- question: commented unreachable code HOT 10
- JSON5.stringify() option: `trailingCommas` HOT 3
- Focus on ESNext HOT 1
- CLI should process consecutive JSONs HOT 1
- migrate to ESModules HOT 3
- Missing LICENSE file in the repo of ver 0.4.0 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from json5.