Code Monkey home page Code Monkey logo

Comments (8)

aseemk avatar aseemk commented on September 25, 2024

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.

tarlepp avatar tarlepp commented on September 25, 2024

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.

aseemk avatar aseemk commented on September 25, 2024

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.

aseemk avatar aseemk commented on September 25, 2024

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.

rlidwka avatar rlidwka commented on September 25, 2024

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

tarlepp avatar tarlepp commented on September 25, 2024

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.

rlidwka avatar rlidwka commented on September 25, 2024

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.

tarlepp avatar tarlepp commented on September 25, 2024

there was a bug in sails.js core and in those cases returned value were converted to string.

from json5.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.