Postman test script generator
Paste or drop your data here, or open a file.
New to Bracely?
Everything stays in your browser.
Output appears here
Paste or open your data in the input box. It never leaves your browser.
Postman Test Script Generator
Writing pm.expect lines for every field of a response is tedious. Paste the response and copy a script for the request's Tests (Post-response) tab: a status test and one test with an assertion for each field, ids and times by type.
Example: a user's profile
A user from GET /users/7. The script checks the status, the user's id by type and every other field exactly, with to.be.null for the null:
The response
{
"id": 7,
"name": "Ananya Rao",
"email": "ananya@example.com",
"role": "admin",
"lastLogin": null
}The request
https://api.example.com/users/7Output
pm.test("Status is 200", function () {
pm.response.to.have.status(200);
});
const body = pm.response.json();
pm.test("The body is as expected", function () {
pm.expect(body.id).to.be.a("number");
pm.expect(body.name).to.eql("Ananya Rao");
pm.expect(body.email).to.eql("ananya@example.com");
pm.expect(body.role).to.eql("admin");
pm.expect(body.lastLogin).to.be.null;
});
How do I use the Postman test script generator?
- Send the request in Postman and copy the response body.
- Paste it here, and set the status the request should return.
- Copy the script into the request's Tests (Post-response) tab.
What does the Postman test script generator do?
- pm.test for the status and the body
- to.eql for stable values, to.be.a for ids and times
- Runs in Bracely's API tests too, without Postman
When to use the Postman test script generator
Postman's Tests tab runs JavaScript after every response, and pm.test with pm.expect is how a collection says what a good response looks like. Those tests are what Newman, the Collection Runner and monitors report on, but writing one assertion per field takes a while.
The script has two tests: the status, then the body, with to.eql for values that stay the same, to.be.a("string") or to.be.a("number") for ids and times, to.have.lengthOf for lists and to.be.null for nulls. Bracely's API tests reads these same assertions, so a collection with this script runs in the browser too, without Postman.
Frequently asked questions
- Where do I paste it?
- In Postman, open the request, then the Scripts tab, then Post-response (called Tests in older versions). It runs every time you send the request.
- Can it save a value for the next request?
- Add a line yourself: pm.environment.set("orderId", body.id); then use {{orderId}} in the next request. API tests in Bracely understands that too.
- Is my data uploaded?
- No. Bracely runs entirely in your browser, so nothing you paste or open leaves your device.
More JSON tools
Bracely has 104 JSON tools in one page. Related ones:
- JSON to TypeScript
- JSON Schema Generator
- JSON to Go
- JSON to Java
- JSON to C#
- JSON to Python
- JSON to Kotlin
- JSON to Swift
- JSON to Dart
- JSON to Rust
- JSON to PHP
- JSON to Zod
- JSON to GraphQL
- JSON to Protobuf
- TOML to JSON
- JSON Lines / NDJSON
- UUID generator
- JSON hash
- CSS to Tailwind
- SQL formatter
- JSON Formatter
- JSON Validator
- JSON Viewer
- JSON Repair
- JSON Diff
- JSON to YAML
- JSON to CSV
- jq Playground
Runs entirely in your browser. Nothing you paste is uploaded. Made by Saurabh Pagrut · About · Privacy policy
Last updated · Version 6.1 · Changelog
Saurabh Pagrut on GitHub · LinkedIn · X · YouTube · Instagram