I am trying to learn JSON, i learned that any javascript object with the key in double quotes are considered as JSON object.
And i constructed this object
You are creating a Javascript Object
. If you want a JSON-string from it, use JSON.stringify
.
So
var myObj = {mykey: "my value"}
,myObjJSON = JSON.stringify(myObj);
Based on comments:
There is no such thing as a JSON Object. There are JSON-strings, which can be parsed
to Javascript Objects. Javascript Objects can be stringified
to JSON strings. Within a JSON-string keys and values are quoted. So the result of the above is a string containing '{"mykey":"my value"}'
.
Try parsing myObjJSON
in your browser console (using: JSON.parse(myObjJSON)
) and you get: Object {mykey: "my value"}
.