JSON to JavaScript object converter
Gives you clean code for JavaScript or TypeScript files instead of JSON full of quoted keys.
Loading the tool…
Processing and privacy: The result is calculated inside your browser and your data is not sent to any server.
How to use it
- Enter json and quotes.
- The result appears straight away and updates as you edit.
- Copy the result, or copy a link that keeps the same values to share it.
How it is calculated
A key is left unquoted when it is a valid identifier such as name or _id, otherwise it is quoted. The key __proto__ is written as a computed key so it stays an ordinary property. Strings escape backslashes, the quote character and line breaks.
Example
Inputs: Quotes = Single '. Result: JavaScript object: { name: 'Ali', age: 30, active: true, tags: [ 'admin', 'editor' ], address: { city: 'Riyadh', zip: null } }; Values converted: 7.
{
"name": "Ali",
"age": 30,
"active": true,
"tags": ["admin", "editor"],
"address": {
"city": "Riyadh",
"zip": null
}
}{
name: 'Ali',
age: 30,
active: true,
tags: [
'admin',
'editor'
],
address: {
city: 'Riyadh',
zip: null
}
}Limits and caveats
- Non-Latin keys stay quoted even when they are valid identifiers.
- At run time JavaScript orders integer-like keys such as "2" and "10" ascending, before other keys.
Questions about this tool
What is the difference between JSON and a JavaScript object?
JSON needs double quotes around every key and string, while a JavaScript object allows unquoted keys, single quotes and trailing commas.
Why are some keys still quoted?
They are not valid identifiers, such as first-name or keys starting with a digit, so they only work in quotes.
Can I use the output in TypeScript?
Yes, the object literal is valid TypeScript as it is.
