Are JSON and Node.js Querystring the same?

Are JSON and Node.js Querystring the same?

Problem

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

Thank you.

Problem courtesy of: Sam

Solution

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 🙂

Solution courtesy of: robertklep

Discussion

Leave a Reply

Your email address will not be published. Required fields are marked *