How should I parse JSON using Node.js? Is there some module which will validate and parse JSON securely?
相关问题
- Is there a limit to how many levels you can nest i
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- How to toggle on Order in ReactJS
- StackExchange API - Deserialize Date in JSON Respo
No further modules need to be required.
Just use
var parsedObj = JSON.parse(yourObj);
I don think there is any security issues regarding this
It's simple, you can convert JSON to string using
JSON.stringify(json_obj)
, and convert string to JSON usingJSON.parse("your json string")
.You can simply use
JSON.parse
.The definition of the
JSON
object is part of the ECMAScript 5 specification. node.js is built on Google Chrome's V8 engine, which adheres to ECMA standard. Therefore, node.js also has a global objectJSON
[docs].Note -
JSON.parse
can tie up the current thread because it is a synchronous method. So if you are planning to parse big JSON objects use a streaming json parser.Leverage Lodash's attempt function to return an error object, which you can handle with the isError function.
Parsing a JSON stream? Use
JSONStream
.https://github.com/dominictarr/JSONStream