---
title: "Convert dotenv files to JSON and back, with dotenv-compatible quoting, escapes, comments, export prefixes and multi-line values, plus validation warnings."
method: POST
path: "/api/v1/env-json"
tags: ["Converters"]
---

# Convert dotenv files to JSON and back, with dotenv-compatible quoting, escapes, comments, export prefixes and multi-line values, plus validation warnings.

`POST /api/v1/env-json`

## Request

- Base URL: `https://programmes.net`
- URL: `https://programmes.net/api/v1/env-json`
- Auth: none declared

.env to JSON Converter. Operations: `to-json` — Parse a .env file into a JSON object (last duplicate wins). `to-env` — Write a JSON object as .env lines, quoting values only where needed. `validate` — Lint a .env file: duplicates, invalid names, unterminated quotes, stray # comments.

## Request body

- union
  - EnvJsonToJson: Parse a .env file into a JSON object (last duplicate wins).
    - `operation` 'to-json', required
    - `input` string: The .env file contents.
    - `options` object
      - `coerceTypes` boolean: Turn true/false/null and plain numbers into JSON types.
      - `indent` integer: JSON indent in spaces.
  - EnvJsonToEnv: Write a JSON object as .env lines, quoting values only where needed.
    - `operation` 'to-env', required
    - `input` string: A JSON object; nested objects are flattened (DB__HOST).
    - `options` object
      - `exportPrefix` boolean: Prefix lines with export.
      - `sortKeys` boolean: Sort keys alphabetically.
      - `uppercase` boolean: Upper-case keys.
      - `separator` string: Separator for nested keys.
  - EnvJsonValidate: Lint a .env file: duplicates, invalid names, unterminated quotes, stray # comments.
    - `operation` 'validate', required
    - `input` string: The .env file contents.
    - `options` object

## Response `200`

The operation ran.

- object
  - `ok` unknown, required
  - `tool` 'env-json', required
  - `operation` 'to-json' | 'to-env' | 'validate', required
  - `result` unknown, required

## Other responses

- `400`: The request is not valid (https://programmes.net/api#invalid-request); The tool has no such operation (https://programmes.net/api#unknown-operation)
- `404`: No such tool (https://programmes.net/api#unknown-tool)
- `413`: The request or its input is too large (https://programmes.net/api#content-too-large)
- `415`: The body must be JSON (https://programmes.net/api#unsupported-media-type)
- `422`: An option is missing, of the wrong type or out of range (https://programmes.net/api#invalid-options); This call needs more CPU than one API call may use (https://programmes.net/api#refused); The operation could not process the input (https://programmes.net/api#tool-error)
- `429`: Too many requests (https://programmes.net/api#rate-limited)
- `500`: Internal error (https://programmes.net/api#internal-error)

---

[API](https://skmtc.dev/programmes/apis/programmes-net-api.md) · [All operations](https://skmtc.dev/programmes/apis/programmes-net-api/llms.txt) · [OpenAPI document](https://skmtc.dev/programmes/apis/programmes-net-api/revisions/aa939784a2e6?raw)
