1
var o = { param1: "value1", param2: "value2" }
console.log(o);
console.log(escape(o));

The first console.log shows Object { param1: "value1", param2: "value2" },

the second: %5Bobject%20Object%5D (i.e. [object Object])

How to serialize an object properly without any plugings?

3
  • possible duplicate of How to serialize & deserialize Javascript objects? Commented Mar 25, 2013 at 11:26
  • @Travis J: Seems to be true. Didn't find it at the beginning. Would you like me to delete this question? P.S. The answer to my question looks more clear, free of unnecessary words. Commented Mar 25, 2013 at 11:41
  • 1
    No need to delete it, the community will decide :) Commented Mar 25, 2013 at 11:42

1 Answer 1

4

It is easier to use JSON serialization:

var serialized = JSON.stringify(o);
// "{"param1":"value1","param2":"value2"}"

You can read about browser compatibility at MDN: https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/JSON#Browser_compatibility

Sign up to request clarification or add additional context in comments.

2 Comments

@Paul - Note also, this is not a plugin but a javascript feature. +1
@Paul JSON object is available in all modern browsers. For the old ones check a shim at MDN (see link in the answer).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.