JSON to Code Literal
Converts JSON into a native literal in Python (dict), PHP (array), Ruby (hash), JavaScript (object) or a pandas DataFrame snippet, with True, None, nil and quoting handled.
- Free
- No sign-up
- Works on any device
About JSON to Code Literal
Pasting JSON straight into source code usually breaks, because null, true and false are spelt differently in each language and the colon is not an arrow. This converter parses the JSON and writes a literal the target language accepts: Python gets True, False and None, PHP gets short array syntax with single-quoted strings and the => arrow, Ruby gets nil and either hash rockets or symbol keys, and JavaScript gets unquoted keys where they are valid names. The pandas option wraps records or column arrays in a DataFrame call.
How to use JSON to Code Literal
- Paste the JSON and choose Python, PHP, Ruby, JavaScript or pandas.
- Set the variable name and indent, and tick trailing commas or the language-specific options.
- Copy the generated literal into your source file or notebook.
Why use this tool?
- Private: everything happens in your browser. Nothing you enter is uploaded.
- Free, with no sign-up, no watermark and no limit on how often you use it.
- Works on phones, tablets and computers: Android, iPhone, Windows, Mac and Linux. Nothing to install.
Also known as
Frequently asked questions
Why did a big number change?
JSON numbers are read as 64-bit floats, so integers with more than about 15 digits can lose precision. Keep such ids as strings in the JSON to preserve every digit.
What happens to an empty JSON object in PHP?
PHP has one array type, so an empty object and an empty array both become an empty array. Numeric string keys also turn into integer keys in PHP, which is how the language treats array keys.
What shape of JSON does the pandas option need?
A list of objects, one per row, or an object whose values are equal-length arrays, one per column. Other shapes show an error because pandas cannot build a table from them directly.
Is JSON to Code Literal free?
Yes. JSON to Code Literal on Toolipedia is free to use, with no sign-up and no watermark.
Is it safe to use?
Yes. Everything is worked out in your browser, and nothing you enter is sent to our server.
Does it work on my phone?
Yes. It works in any modern browser on Android and iPhone, as well as on tablets and computers. There's nothing to install.
Do I need an account?
No. Just open the page and use the tool. There's no sign-up and no email needed.