Convert JSON to JavaScript object

Why bother converting JSON to a JavaScript object?

Have you ever copied JSON snippets to use them in your JavaScript code? Did you have to replace or remove all the quotes to comply with your JavaScript code guidelines? This simple online tool will help you with this task: just paste a JSON string and get back a valid JavaScript object with all extra quotes removed and replaced.

Paste your JSON object here

{ "sender":{ "id":"USER_ID" }, "recipient":{ "id":"PAGE_ID" }, "timestamp":1458692752478, "message":{ "mid":"mid.1457764197618:41d102a3e1ae206a38", "seq":73, "text":"hello, world!", "quick_reply": { "payload": "DEVELOPER_DEFINED_PAYLOAD" } } }

JS version appears here

What is JSON Object Literal?

JSON object literal has the following syntax rules:

  1. keys must be strings;
  2. values can be strings, numbers, objects, arrays, true, false or null.

Unlike the JavaScript object literal, strings must be always enclosed in double quotes. Additionally, JSON does not allow trailing commas, whereas many JavaScript style guides require them as it is allowed in JavaScript object literals.

Don't like an online tool to convert JSON to JS?

Install a CLI tool json-to-js by running

npm i -g json-to-js
and use it as follows:
pbpaste | json-to-js | pbcopy
Copy your JSON, run this snippet and paste a JS object, ready to be used in your code.

Acknowledgment relies on the following open source projects: ace editor, clipboardjs and the javascript-stringify library.