You commit a Postman collection export to the repo. Someone changes one number in a request body. The pull request shows the whole body deleted and added again, on a single line, full of \n and \". Reviewers approve it without reading it, because there's nothing readable there.
That's common enough that people write tools for it. There's a gist with a jq diff driver whose whole explanation is one sentence: an export stores the body "in the 'raw' property as a single string", so "the whole line has changed". There's postbox, which splits a collection "into files. One file per request". And Thunder Client users opened an issue about resolving merge conflicts in one shared collection file by hand.
We make Baton, an API client that keeps requests as YAML in your repository, so we have an interest here. Instead of arguing it, we made the same two edits to the same request in both formats and looked at what git diff prints. One of the two results goes against us, and it's shown in full.
First: which Postman?
This matters more than it did a year ago. Postman v12 has Native Git, and in Local View it saves collections in schema 3.0.0: YAML on disk, one *.request.yaml file per request, and a sibling .resources directory per request with its examples and scripts. Postman says the format exists so people and tools can "read, diff, review, and safely change collections in the same way as source code."
We haven't measured v3 diffs. If your team is on Native Git with v3 files, the Postman half of this article isn't about you, and you should run the two edits below on your own files before believing anyone, us included.
The v2.1 JSON export is still around, though. Postman's own schema page notes that in v12 "Newman can run a Postman Collection exported to the 2.1.0 format, but it can't run 3.0 collections". Any repo whose CI runs Newman holds a v2.1 file, and that's the file the gist was written for. That's what we compared.
The setup
One request: POST {{baseUrl}}/workshop/api/shop/orders, a JSON body with three fields, a Content-Type header and one test that checks the status code.
- Postman side: a v2.1 collection containing that one request, built to the v2.1.0 schema, tab-indented the way the app exports. The body sits in
body.rawas a string; the test sits inevent[].script.execas an array of lines. - Baton side: the same request written by
@dudko.dev/baton-format0.1.3, the format's published npm package, run on Node 24. In a workspace each request is its own.req.yamlfile undercollections/<name>/.
Here's the whole Baton file:
format: 1 id: 01JD0000000000000000000000 name: Create order method: POST url: "{{baseUrl}}/workshop/api/shop/orders" headers: - name: Content-Type value: application/json body: type: json json: |- { "product_id": 1, "quantity": 1, "coupon": "TRAC075" } scripts: tests: "pm.test(\"status\", () => {\n pm.response.to.have.status(200);\n});\n" 18 lines. The Postman export of the same request is 56, but line count isn't the point. Look at the last line of the Baton file, it comes back in a minute.
Edit 1: change a value in the body
quantity goes from 1 to 2.
Postman v2.1 export:
@@ -30,7 +30,7 @@ "body": { "mode": "raw", - "raw": "{\n \"product_id\": 1,\n \"quantity\": 1,\n \"coupon\": \"TRAC075\"\n}", + "raw": "{\n \"product_id\": 1,\n \"quantity\": 2,\n \"coupon\": \"TRAC075\"\n}", "options": { Baton:
@@ -11,7 +11,7 @@ body: json: |- { "product_id": 1, - "quantity": 1, + "quantity": 2, "coupon": "TRAC075" } This is the gist's problem exactly. Here the body has three fields, so you can still find the change. With a real payload of forty lines, the raw line is one very long string and the reviewer is hunting for a single character. Baton writes a JSON body as a YAML block scalar (json: |-), so the body keeps its own lines and the diff is the line that changed.
If you're staying on v2.1 exports, the gist's fix works. We ran its jq filter (jq 1.7) as a textconv on both files and got a clean one-line "quantity": 2 diff. Two limits worth knowing. Its filter walks .item[], which is the top level only, so requests inside folders need a recursive version. And textconv runs in your local git diff; the pull request page on GitHub won't use it, and that's where review usually happens.
Edit 2: change the test
The expected status goes from 200 to 201. This is where Baton loses.
Postman v2.1 export:
@@ -13,7 +13,7 @@ "exec": [ "pm.test(\"status\", () => {", - " pm.response.to.have.status(200);", + " pm.response.to.have.status(201);", "});" ], Baton:
@@ -15,4 +15,4 @@ body: "coupon": "TRAC075" } scripts: - tests: "pm.test(\"status\", () => {\n pm.response.to.have.status(200);\n});\n" + tests: "pm.test(\"status\", () => {\n pm.response.to.have.status(201);\n});\n" baton-format 0.1.3 writes every multi-line script as one double-quoted string with \n escapes. We tried four multi-line scripts, with and without a trailing newline, and all four came out quoted. So a one-character change to a script rewrites the whole script on one line, which is the same problem the Postman export has with bodies, moved to a different field. The exec array, one element per line, diffs better.
For a three-line test that's tolerable. For a fifty-line pre-request script it's the unreadable diff this article started with. Until the format writes scripts as block scalars, git diff --word-diff narrows it down locally:
tests: "pm.test(\"status\", () => {\n [-pm.response.to.have.status(200);\n});\n"-]{+pm.response.to.have.status(201);\n});\n"+} Better than nothing. Not as good as a proper line diff.
Merge conflicts
We didn't measure conflict rates, so here's only what follows from the file layout. A v2.1 export is one file for the whole collection: every change from every person lands in it, and the Thunder Client issue is what resolving that by hand looks like. (Thunder Client has since shipped a new storage design to reduce those conflicts, and the issue is closed.) postbox gets a Postman user part of the way by splitting the export into one file per request.
In Baton, and in Postman's v3 files, one request is one file. Two people editing two different requests touch two different files, and there's nothing for git to reconcile.
Does the file stay stable?
A diff is only readable if the tool doesn't rewrite things you didn't touch. We parsed each of the three Baton files and serialised it again: byte-identical every time. The package README goes further and says the format is implemented a second time in Dart for the app, with both implementations "pinned to byte-level conformance fixtures". That's their claim; we've only tested the JavaScript side.
Reproduce it
Node 24, npm i @dudko.dev/baton-format, then:
// baton-diff.mjs: writes before/after files, then: git diff --no-index a.yaml b.yaml import { serializeRequestFile, parseRequestFile } from "@dudko.dev/baton-format"; import { writeFileSync } from "node:fs"; const request = (quantity, status) => ({ format: 1, id: "01JD0000000000000000000000", name: "Create order", method: "POST", url: "{{baseUrl}}/workshop/api/shop/orders", query: [], headers: [{ name: "Content-Type", value: "application/json", enabled: true }], auth: { type: "inherit" }, body: { type: "json", json: JSON.stringify({ product_id: 1, quantity, coupon: "TRAC075" }, null, 2), }, scripts: { tests: `pm.test("status", () => {\n pm.response.to.have.status(${status});\n});\n`, }, presets: [], meta: { tags: [] }, }); for (const [file, quantity, status] of [["a", 1, 200], ["b", 2, 200], ["c", 1, 201]]) { const text = serializeRequestFile(request(quantity, status)); writeFileSync(`${file}.yaml`, text); console.log(file, "round trip identical:", serializeRequestFile(parseRequestFile(text)) === text); } git diff --no-index a.yaml b.yaml is the body edit, a.yaml c.yaml the test edit. For the Postman side, export any request with a JSON body from the app in v2.1 format, change one value, and diff.
So which one?
- Postman v12 with Native Git: you're on v3 YAML already. Check your own diffs; the v2.1 numbers here don't describe you.
- Postman v2.1 exports, because Newman runs them: add the gist's textconv for local review, extend its filter to folders, and accept that the GitHub PR view will still show the raw string.
- Baton: body edits diff line by line, one request is one file, and the output is deterministic. Script edits don't diff well yet, and if your collections are mostly long scripts that's a real cost today.
The Baton demo runs in the browser at baton.dudko.dev/demo, with nothing to install, if you want to see what the files look like from the app side.
Originally published at https://baton.dudko.dev/blog/postman-collection-git-diff.
