Sam
Sam

Reputation: 3559

Are JSON and Node.js Querystring the same?

On node.js, are JSON methods (parse, stringify) the same as Query Sting methods (parse, stringify) ?

Thank you.

Upvotes: 11

Views: 11557

Answers (2)

user529758
user529758

Reputation:

Talking names. The query string methods return strings suitable for use in a URL query string. I. e., they are percent-escaped. That's not at all related to JSON.

Upvotes: 2

robertklep
robertklep

Reputation: 203494

Let's try:

var qs  = require('querystring');
var obj = { 'foo' : '1 + 2' };

console.log(qs.stringify(obj));
// result: foo=1%20%2B%202

console.log(JSON.stringify(obj));
// result: {"foo":"1 + 2"}

So, no, they aren't :-)

Upvotes: 30

Related Questions