MJS JSON
Not possible

Convert MJS to JSON

Can you convert MJS to JSON?
QUICK ANSWER
Is it possible to convert MJS to JSON?
No - not a direct conversion.

You cannot turn code into JSON directly. The realistic path is to run the .mjs module, take the object it exports, and write it out with JSON.stringify, which only works if that object contains plain data (no functions, no logic).

No direct path
Also to JSON: BDOB · EXPRESS · REPLIT

On this page

Tested on macOS, Windows & Linux
Last verified Sep 2026

More free converters

HEIC, PNG, WEBP, MP3 and more - every tool here is free.

Open the toolbox

Why convert MJS to JSON?

Sometimes a config or fixture lives in an .mjs module and you need it as a static .json file that other tools can read without running JavaScript, so you execute the module and serialize its exported value.

How to convert MJS to JSON

Node.js one-liner FREE

Import the module and print JSON: node --input-type=module -e "import('./file.mjs').then(m=>console.log(JSON.stringify(m.default,null,2)))" > file.json.

Small Node script FREE

Write a short .mjs that does import data from './file.mjs' then fs.writeFileSync('file.json', JSON.stringify(data, null, 2)) and run it with node.

Visual Studio Code FREE

If the .mjs already exports a plain object literal, copy that object into a new .json file and remove the export keyword, quoting all keys.

About these formats

Quality & what to watch

  • Only serializable data survives: functions, classes, undefined, BigInt, symbols and comments are dropped or throw during JSON.stringify.
  • Running the module executes its code, so any side effects (network calls, file writes) happen during conversion.
  • If the module builds its export dynamically at runtime, the JSON is only a snapshot of one particular run.

Frequently asked questions

Why can't I convert `.mjs` straight to `.json`?
.mjs is executable code that can contain logic, imports and functions, while JSON holds only static values. There is nothing to convert unless you run the code first.
How do I get JSON out of an `.mjs`?
Run the module in Node, take its exported object, and pass it to JSON.stringify. Write the result to a .json file.
What gets lost?
Anything JSON cannot represent: functions, classes, undefined, BigInt, symbols and comments. Only plain data remains.
Is there an online tool for this?
No safe one exists, because it would have to execute your JavaScript. Run it yourself locally with Node instead.