JS Object to JSON Converter
Convert JavaScript object literals to valid JSON — quote keys, fix quotes, strip comments
You copied an object literal from your JavaScript or TypeScript code, but it is not valid JSON — unquoted keys, single-quoted strings, trailing commas, and comments make it unparseable by JSON.parse(). You need to convert it to strict JSON for an API request, configuration file, or data exchange.
Why JavaScript Objects Are Not Valid JSON
JavaScript object literals and JSON look similar but have key differences:
| Feature | JavaScript Object | JSON |
|---|---|---|
| Key quoting | Optional ({ name: "Alice" }) | Required ({ "name": "Alice" }) |
| String quotes | Single or double | Double only |
| Trailing commas | Allowed ([1, 2,]) | Not allowed |
| Comments | // line and /* block */ | Not allowed |
undefined | Valid value | Not valid |
NaN, Infinity | Valid values | Not valid |
| Template literals | `hello ${name}` | Not valid |
How This Converter Works
Paste a JavaScript object literal and the tool outputs valid JSON:
- Key quoting: Unquoted keys like
namebecome"name" - Quote normalization: Single-quoted strings
'hello'become"hello" - Trailing comma removal:
[1, 2, 3,]becomes[1, 2, 3] - Comment stripping: Both
//and/* */comments are removed - Undefined handling:
undefinedvalues are converted tonull - Pretty printing: Output is formatted with configurable indentation
Common Use Cases
API testing — Copy an object from your code, convert to JSON, and paste into Postman, Insomnia, or curl for API testing.
Configuration files — Convert JavaScript config objects to JSON for package.json, tsconfig.json, or other JSON-based configuration files.
Data migration — Extract data objects from JavaScript source code and convert to JSON for import into databases or other systems.
Documentation — Convert code examples from JavaScript to JSON format for API documentation and README files.
Frequently Asked Questions
Q: What happens to functions and symbols in the object?
A: Functions, Symbol values, and other non-serializable values are removed from the output, matching JSON.stringify() behavior. Properties with function values are omitted entirely.
Q: Are nested objects handled? A: Yes. The converter processes objects at any depth, applying key quoting, quote normalization, and trailing comma removal recursively through all nested objects and arrays.
Q: How are ES6+ features handled?
A: Computed property names ([key]: value), shorthand properties ({ name }), and spread syntax (...obj) cannot be evaluated without runtime context and are not supported. Use only literal key-value pairs.
Q: Is my code sent to a server? A: No. All parsing and conversion happens entirely in your browser. Your JavaScript code never leaves your device.