DEV Community

Cover image for Working with JSON Data in Bruno
Ryan Reynolds
Ryan Reynolds

Posted on • Originally published at blog.usebruno.com

Working with JSON Data in Bruno

JSON (JavaScript Object Notation) is the go-to format for sending and receiving data in modern web APIs. Its simplicity, readability, and wide support across programming languages make it a favorite among developers. While XML had its moment, JSON has clearly taken the lead, especially in the world of REST APIs.

In this guide, we’ll walk through the basics of JSON architecture and structure, followed by real-world examples of how to access and test JSON properties using Bruno—an open-source, Git-sync'd, API client that puts developers first.


A Quick Primer on JSON

JSON represents data as key-value pairs and supports objects, arrays, strings, numbers, booleans, and null values. Here’s a simple JSON object:

{
  "name": "Bruno",
  "email": "hello@usebruno.com",
  "twitter": "@use_bruno",
  "github": "usebruno"
}
Enter fullscreen mode Exit fullscreen mode

And here's a more complex nested structure:

{
  "items": [
    {
      "orderID": "0000001211",
      "orderInvoiceNo": "1234567",
      "OrderBlocks": [
        {
          "lineNo": 1,
          "productCode": "001"
        },
        {
          "lineNo": 2,
          "productCode": "012"
        }
      ]
    }
  ]
}
Enter fullscreen mode Exit fullscreen mode

Despite its nested nature, the data is easy to work with in Bruno thanks to its built-in JSON viewer, which formats responses cleanly and makes it easy to collapse and expand sections.

Bruno JSON Viewer


Real-World Bruno Test Examples

Want to try this yourself? All examples are available in a public GitHub collection. You can clone it directly, or use the "Fetch in Bruno" button to import them instantly.

✅ Example 1: Validate Key Names and Values

test("OrderBlock has expected lineNo and productCode", () => {
  const jsonData = res.getBody();
  const firstBlock = jsonData?.items?.[0]?.OrderBlocks?.[0];

  expect(firstBlock).to.have.property("lineNo");
  expect(firstBlock).to.have.property("productCode");

  expect(firstBlock.lineNo).to.equal(1);
  expect(firstBlock.productCode).to.equal("001");
});
Enter fullscreen mode Exit fullscreen mode

✅ Example 2: Find a Block by lineNo

test("Find OrderBlock by lineNo", () => {
  const jsonData = res.getBody();
  const blocks = jsonData?.items?.[0]?.OrderBlocks;

  const match = blocks.find(b => b.lineNo === 3);

  expect(match).to.be.an("object");
  expect(match.productCode).to.equal("013");
});
Enter fullscreen mode Exit fullscreen mode

✅ Example 3: Flatten Nested Arrays of lineNo Values

test("Flatten all lineNo arrays", () => {
  const jsonData = res.getBody();
  const blocks = jsonData?.items?.[0]?.OrderBlocks;

  const allLineNos = blocks.flatMap(b => b.lineNo);

  console.log("All lineNos:", allLineNos);
  expect(allLineNos.length).to.be.greaterThan(0);
});
Enter fullscreen mode Exit fullscreen mode

Try It Yourself in Bruno

You can run these tests by cloning the public collection on GitHub. Just click the button below to fetch it directly in Bruno:

Fetch in Bruno

Or clone the repo directly: https://github.com/bruno-collections/json-testing-examples


Final Thoughts

JSON is foundational to modern APIs, and Bruno makes working with it simple and elegant. Whether you're debugging a response, writing a test, or building a mock, Bruno helps you focus on what matters — your data.

To learn more, check out the Bruno docs or join the Bruno Discord.

Top comments (0)