Search code examples
javascriptjsonstringify

How to convert javascript object into json without using "JSON.stringify" method?


Is there any way to convert javascript object into JSON.

I can not use

JSON.stringify(<obj>)

Because there is no stringify method in the JSON object in the following link.

Link

Example:

var obj = {'x':1,'y':2}

Now if I'll run

console.log(JSON.stringify(obj));

Then I'm getting this error.

error: TypeError: Object # has no method 'stringify'


Solution

  • Well, the website overrides the actual JSON object with their own.

    > JSON
    > Object {toStr: function, quote: function}
    

    Try using JSON.toStr(object)