Dev · 108 tools · nothing uploads

.env ↔ JSON

Convert a .env file to a flat JSON object and back. Values are treated as strings both ways. No nesting, no type coercion of numbers/booleans on the JSON->env direction beyond JSON.stringify. Runs on your device.

Input

Options

live

.env to JSON reads every KEY=VALUE line, allowing an optional export prefix, and strips one matching pair of quotes from the value. Blank lines and comment lines are skipped, and so is any line that does not match. Set mode to json-to-env for the return trip. A ${OTHER_VAR} reference is copied as literal text, never expanded.

Questions

Which way does it convert?

Both, chosen by the mode option, which defaults to env-to-json. That direction reads a .env file and gives a flat JSON object printed with 2-space indentation. The json-to-env direction takes a flat JSON object and writes KEY=value lines, one per key, in the order the object lists them.

Which lines of my .env are read?

Lines of the form KEY=VALUE, where KEY starts with a letter or underscore and continues with letters, digits or underscores. An optional export prefix is accepted. Blank lines and lines starting with # are skipped, and any other line that does not match is skipped silently rather than causing an error.

What happens to quotes around a value?

A matching pair of single or double quotes wrapping the whole value is removed, and everything inside is taken as written. There is no escape processing, so a backslash-n inside the quotes stays two characters, and a multi-line value written across several lines will not be read as one value.

Does it expand ${OTHER_VAR} references?

No. Values are copied as written, so a reference to another variable stays as literal text in the JSON. Nothing is resolved, substituted or read from your actual environment, and no shell is involved. That also means a value which depends on another one will not be expanded on the way back either.

What does the JSON to .env direction do with quoting?

It quotes a value only when it contains whitespace, a double quote or a hash, and escapes any inner double quotes. Values that are not strings are written through JSON stringify, so numbers and booleans become their plain text and an object becomes JSON on one line. A top-level array or non-object is refused with "expected a flat JSON object of key/value pairs".

Is a round trip lossless?

The keys and values survive; the presentation does not. Comments, blank lines, the export prefix and the original ordering of quoting are not preserved, and if a key appears twice the last one wins. Also, your .env likely holds secrets, which is a good reason to note that this runs entirely in a Web Worker on your device.

Related Dev tools

n→nJSON format / validateParse, validate and pretty-print JSON, with a clear parse-error message if it is broken.Runs on each file you dropn→nJSON sort / minify / escapeSort object keys, minify to one line, or escape/unescape JSON for embedding inside another string.Runs on each file you dropn→nJSONPath queryQuery JSON with a JSONPath expression: dot/bracket access, wildcards (*), recursive descent (..). No filter expressions (?()) or slices; those need a full JSONPath engine this build does not have.Runs on each file you dropn→nJSON Schema generatorInfer a draft-07 JSON Schema from an example JSON document. Every observed key is marked required, arrays are typed to accept every observed element.Runs on each file you dropn→nJSON to TypeScriptJSON to TypeScript. Infers types from an example JSON document. Nested objects become named types by their key; mixed-type arrays fall back to a broad/any type.Runs on each file you dropn→nJSON to GoJSON to Go. Infers types from an example JSON document. Nested objects become named types by their key; mixed-type arrays fall back to a broad/any type.Runs on each file you dropn→nJSON to RustJSON to Rust. Infers types from an example JSON document. Nested objects become named types by their key; mixed-type arrays fall back to a broad/any type.Runs on each file you dropn→nJSON ↔ CSVConvert a flat JSON array of objects to CSV and back. CSV has no type system: JSON->CSV renders numbers/booleans/null as text and CSV->JSON always comes back as strings. A nested object or array field is refused by name rather than silently flattened. CSV parsing is fully quote-aware, embedded newlines included; a file with an unterminated quote is refused rather than guessed at.Runs on each file you drop