HTTPie: How to Send JSON

Updated

Learn how to send JSON payloads, nested objects, and files using HTTPie

HTTPie: How to Send JSON

Before we start, make sure you have HTTPie installed on your computer. If you don't have it yet, install it with Homebrew:

brew install httpie

Send JSON Key-Value Pairs

HTTPie sends request data as JSON by default, sets the Content-Type: application/json header automatically, and defaults to a POST request whenever you pass data. Use = for strings and := for raw JSON types like numbers, booleans, arrays, and nested objects:

http POST https://example.com name="Jane Doe" age:=30 active:=true roles:='["admin", "editor"]' meta:='{"department": "engineering"}'

Just remember to replace https://example.com with your own endpoint. If you want to inspect the exact HTTP request and JSON body before sending anything, add the --offline flag.

Send Raw JSON or a JSON File

For deeply nested payloads or existing files, you can pipe raw JSON via standard input or redirect a local .json file:

echo '{"user": {"id": 42, "status": "active"}}' | http POST https://example.com
http POST https://example.com < payload.json

To embed a JSON file into a single field instead of the whole body, use :=@ followed by the file name:

http POST https://example.com name="Jane" profile:=@profile.json
undefined

If you ever need to send an explicit JSON Accept header without attaching a request body, just add --json (or -j) to the command.