# How do I parse and validate a JSON response?

> How to parse and validate JSON responses in a Loadster test script, to verify your API returns the expected data under heavy traffic.

Source: https://loadster.com/faqs/parse-a-json-response/

If you're load testing a JSON web service, or something similar, it's important to validate that the responses coming
back are of a valid JSON format and are structured correctly. Furthermore, it's often important to look for certain
pieces of data in the response to make sure it's correct.

The easy way to do this in Loadster is with the "Validate with JavaScript" feature. Expand the **Add...** menu on the
step you want to validate, and select **Validate with JavaScript** from the menu.

_Figure: Adding a JavaScript validator_


This type of validator lets you write a custom JavaScript function to evaluate the response.

_Figure: Parsing a JSON array and looking at the first item_


To parse the JSON into a JavaScript object, use the standard `JSON.parse` function.

The important thing about validation functions is that they're expected to return a boolean value: `true` if the
response is valid, and `false` if it's invalid. In the above example, we're only considering the response valid if the
response is a JSON array with at least 1 item, and the first item has a `firstName` of "Alice".

You can read more about validation in Loadster, and other types of validators, in
[Validation Rules](https://loadster.com/manual/protocol-scripts/validation-rules/).

JSON parsing also works in [Capturing Rules](https://loadster.com/manual/protocol-scripts/capturing-rules/).

