Skip to main content

JSON File Format Reference

Mercury stores requests as JSON files — a structured, machine-readable format with excellent tooling support. This page documents the complete specification.

Overview

A .json request file contains a single HTTP request as a JSON object:

{
"method": "GET",
"url": "https://api.example.com/users",
"headers": {},
"body": ""
}

Schema

FieldTypeRequiredDescription
methodstringYesHTTP method (GET, POST, PUT, etc.)
urlstringYesFull URL including protocol
headersobjectYesKey-value pairs of HTTP headers
bodystringYesRequest body (empty string if none)

Method

The method field specifies the HTTP verb.

Supported Methods

MethodDescription
GETRetrieve resource
POSTCreate resource
PUTReplace resource
PATCHPartial update
DELETERemove resource
HEADGet headers only
OPTIONSGet allowed methods

Methods should be UPPERCASE.

URL

URLs must include the protocol:

{
"method": "GET",
"url": "https://api.example.com/users"
}
warning

URLs without protocol (e.g., api.example.com/users) are invalid.

Headers

Headers are stored as a JSON object with key-value pairs:

{
"method": "GET",
"url": "https://api.example.com/users",
"headers": {
"Accept": "application/json",
"Authorization": "Bearer token123",
"X-Custom-Header": "my-value"
},
"body": ""
}

Common Headers

HeaderPurposeExample
AuthorizationAuthenticationBearer token123
Content-TypeBody formatapplication/json
AcceptExpected response formatapplication/json
User-AgentClient identificationMercury/1.0
Cache-ControlCaching behaviorno-cache

Body

The body field contains the request payload as a string.

JSON Body

For JSON payloads, escape the JSON within the string:

{
"method": "POST",
"url": "https://api.example.com/users",
"headers": {
"Content-Type": "application/json"
},
"body": "{\"name\": \"John Doe\", \"email\": \"john@example.com\"}"
}

Form Data

{
"method": "POST",
"url": "https://api.example.com/login",
"headers": {
"Content-Type": "application/x-www-form-urlencoded"
},
"body": "username=john&password=secret"
}

No Body

For GET, HEAD, and OPTIONS, use an empty string:

{
"method": "GET",
"url": "https://api.example.com/users",
"headers": {
"Accept": "application/json"
},
"body": ""
}

Variables

Use {{variable}} syntax for dynamic values. Variables work in URL, headers, and body:

{
"method": "GET",
"url": "{{BASE_URL}}/users/{{USER_ID}}",
"headers": {
"Authorization": "Bearer {{API_TOKEN}}"
},
"body": ""
}

Variable Substitution

Variables are replaced with values from .env files:

# .env
BASE_URL=https://api.example.com
USER_ID=12345
API_TOKEN=secret123

Variable Rules

  • Variable names are case-sensitive
  • Undefined variables are sent as literal text ({{UNDEFINED}})
  • No spaces inside braces: {{VALID}}, not {{ INVALID }}

Complete Examples

GET with Authentication

{
"method": "GET",
"url": "https://api.example.com/users",
"headers": {
"Authorization": "Bearer {{API_TOKEN}}",
"Accept": "application/json"
},
"body": ""
}

POST with JSON

{
"method": "POST",
"url": "https://api.example.com/users",
"headers": {
"Content-Type": "application/json",
"Authorization": "Bearer {{API_TOKEN}}"
},
"body": "{\"name\": \"Jane Doe\", \"email\": \"jane@example.com\", \"role\": \"admin\"}"
}

PUT Update

{
"method": "PUT",
"url": "https://api.example.com/users/{{USER_ID}}",
"headers": {
"Content-Type": "application/json"
},
"body": "{\"name\": \"Updated Name\"}"
}

DELETE

{
"method": "DELETE",
"url": "https://api.example.com/users/{{USER_ID}}",
"headers": {
"Authorization": "Bearer {{API_TOKEN}}"
},
"body": ""
}

Multiple Headers

{
"method": "GET",
"url": "https://api.example.com/data",
"headers": {
"Authorization": "Bearer {{TOKEN}}",
"Accept": "application/json",
"Accept-Language": "en-US",
"X-Request-ID": "{{REQUEST_ID}}",
"X-API-Version": "2",
"Cache-Control": "no-cache"
},
"body": ""
}

File Organization

A typical workspace structure:

my-api-project/
├── .env # Default environment
├── .env.development # Dev overrides
├── .env.production # Prod overrides
├── users/
│ ├── get-user.json # GET /users/:id
│ ├── list-users.json # GET /users
│ └── create-user.json # POST /users
└── products/
├── list.json
└── create.json