Overview
The JsonParser block parses JSON strings into JavaScript objects so you can access their properties in assertions and subsequent blocks.Input Parameters
Required
Parameter | Type | Description |
---|---|---|
body | string | JSON string to parse |
Output Fields
On Success
Field | Type | Description |
---|---|---|
parsed | object/array | The parsed JSON data |
On Failure
Field | Type | Description |
---|---|---|
error | string | Error message describing parse failure |
raw | string | Original unparsed body |
Examples
Basic Usage
- HttpRequest returns:
{ body: '{"id": 1, "name": "John"}' }
- JsonParser parses to:
{ parsed: { id: 1, name: "John" } }
- Stored in DataBus as:
user = { id: 1, name: "John" }
- Assertions can access
user.id
anduser.name
Using String Input Format
{ body: value }
:
Access with: ${parsed.parsed.id}
Using Object Format (Recommended)
${user.id}
(cleaner!)
Parsing Arrays
Error Handling
If parsing fails, the block returns an error:Common Patterns
HTTP Request + Parse
Nested Data Extraction
Multiple Parse Operations
Full Example
Tips
Always Use Object Output Format
Always Use Object Output Format
Map
parsed
to a descriptive name for cleaner references:Handle Parse Errors Gracefully
Handle Parse Errors Gracefully
Check if parsing succeeded before making assertions:If
parsed
doesn’t exist (parse failed), assertion will fail with clear message.Parse Before Validation
Parse Before Validation
Always parse JSON before using validation blocks:
When to Use
Use JsonParser when:- Parsing HTTP response bodies
- Converting JSON strings to objects
- Accessing nested JSON properties
- Response is already an object (not common in SemanticTest)
- Parsing streaming responses (use StreamParser)