PureDevTools

JS Object to JSON Converter

Convert JavaScript object literals to valid JSON — quote keys, fix quotes, strip comments

All processing happens in your browser. No data is sent to any server.
Indent:
JavaScript Object
JSON Output

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:

FeatureJavaScript ObjectJSON
Key quotingOptional ({ name: "Alice" })Required ({ "name": "Alice" })
String quotesSingle or doubleDouble only
Trailing commasAllowed ([1, 2,])Not allowed
Comments// line and /* block */Not allowed
undefinedValid valueNot valid
NaN, InfinityValid valuesNot valid
Template literals`hello ${name}`Not valid

How This Converter Works

Paste a JavaScript object literal and the tool outputs valid JSON:

  1. Key quoting: Unquoted keys like name become "name"
  2. Quote normalization: Single-quoted strings 'hello' become "hello"
  3. Trailing comma removal: [1, 2, 3,] becomes [1, 2, 3]
  4. Comment stripping: Both // and /* */ comments are removed
  5. Undefined handling: undefined values are converted to null
  6. 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.

Related Tools

More JSON Tools