Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial match on json body assertion #3781

Open
sdil opened this issue Feb 25, 2025 · 2 comments
Open

Partial match on json body assertion #3781

sdil opened this issue Feb 25, 2025 · 2 comments
Labels
enhancement New feature or request

Comments

@sdil
Copy link

sdil commented Feb 25, 2025

Problem to solve

Imagine I have the following response body

{
  "id":"01953a93-0849-7f7f-af5b-3771899d2e6c",
  "title":"Title 1",
  "amount":10,
  "description":"Description 1"
}

The ID returned by the server is UUID. How can I assert the whole JSON object except the ID? I'm trying to avoid JSONPath because it gets very long and hard to maintain when the response has so many fields.

@sdil sdil added the enhancement New feature or request label Feb 25, 2025
@jcamiel
Copy link
Collaborator

jcamiel commented Feb 25, 2025

Hi @sdil

What you can do is capture the id field with a jsonpath and inject it in the body assert:

GET https://foo.com
HTTP 200
[Captures]
id: jsonpath "$.id"
{
  "id":"{{id}}",
  "title": "Title 1",
  "amount":10,
  "description":"Description"
}

Note: the assert is whitespace sensitive so this snippet assumes you're receiving this JSON exactly with spaces and newlines.

@sdil
Copy link
Author

sdil commented Feb 25, 2025

Ahh that's what I need. I'll give it a try. Thanks alot @jcamiel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants