JSON to JavaScript Converter

Convert JSON strings into valid JavaScript objects and variables. Generates clean ES6 exports ready to use in your source code.

Auto-converts live as you paste or type (or press Ctrl+Enter)

1
Output will appear here...

JSON vs JavaScript objects

Although JSON (JavaScript Object Notation) was derived from JavaScript syntax, the two formats are not the same. JSON is a strict data interchange format where all keys must be double-quoted strings and values must be one of six specific types. JavaScript object literals are more flexible: keys can be unquoted, values can be functions, and the syntax allows trailing commas and comments.

This converter takes valid JSON and wraps it in a JavaScript ES6 export statement so you can drop it directly into a .js or .mjs source file.

How to use:

  1. Paste your JSON into the input editor.
  2. Click Convert to JS.
  3. Copy the JavaScript output or download it as a .js file.

Example conversion

JSON input:

{
  "apiUrl": "https://api.example.com",
  "timeout": 5000,
  "retries": 3
}

JavaScript output:

export default {
  apiUrl: "https://api.example.com",
  timeout: 5000,
  retries: 3
};

Common use cases

  • Converting a JSON config file into a JavaScript module for a Node.js project
  • Embedding API response data as a fixture for unit tests
  • Creating static data files for a frontend application
  • Migrating a .json file to an ES module format

Related Tools