About the JSON Serialize
Serialize a JSON value, or a relaxed JavaScript object literal with unquoted keys and single quotes, into a strict, compact JSON string.
Key features
- Accepts strict JSON or relaxed JavaScript object literals
- Handles unquoted keys, single quotes and trailing commas
- Outputs compact, standards-compliant JSON
- Converts JS values like True/None to JSON equivalents where possible
- Validates the result
- Runs locally in your browser
From object literal to strict JSON
Developers constantly copy objects out of JavaScript code, browser consoles, Python REPLs and documentation, then need them as valid JSON for an API request, a config file or a test. JavaScript's object syntax is looser than JSON, so a direct copy usually fails to parse. JSON Serialize accepts the loose version and gives you compact, strict JSON.
Example
Input (a JavaScript object literal):
{ name: 'Ada', languages: ['en', 'fr'], active: true, }
Serialized JSON:
{"name":"Ada","languages":["en","fr"],"active":true}
What gets fixed
| Relaxed syntax | Becomes |
|---|---|
{name: 1} unquoted key | {"name":1} |
'single' quotes | "single" |
Trailing commas [1,2,] | [1,2] |
// comments | removed |
True / False / None (Python) | true / false / null |
Serialization in popular languages
JSON.stringify(obj) // JavaScript
json.dumps(obj, separators=(",", ":")) # Python, compact
JsonSerializer.Serialize(obj) // C# System.Text.Json
new ObjectMapper().writeValueAsString(obj) // Java Jackson
When to use it
- Postman / curl bodies written from object literals in docs.
- Storing objects in a database string column or cache.
- Fixtures and mocks copied from console output.
- Converting Python dict output into JSON (for simple values).
Related tools
Reverse the process with JSON Deserialize. For heavily broken JSON, the JSON Fixer offers more control and pretty output. To embed the result inside another JSON string, use JSON Stringify.
How to use the JSON Serialize
- Paste your data into the input box, upload a file, or click Sample to try it out.
- Adjust the options above the editor if you need to (indentation, delimiter, and so on).
- The result appears instantly in the output panel. Any errors are shown with their line and column.
- Click Copy to copy the result, or Download to save it as a file.