question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is there a way to check nested json?

See original GitHub issue

Hi,

we have an API that hands out an stream of objects that look like this:

[
      {
        "Id": "123",
        "Title": "Thing",
        "Updated": "2022-01-20T11:45:09.8861475+01:00",
        "Content": "{\"DocumentenID\":\"88c85db4-a02a-400f-9376-108acd146559\",\"Filetype\":\"thing\",\"DocRevisionType\":2,\"FakturierungsID\":\"cd7215cf-d998-430a-9ec1-9a8d590c2e64\",\"AggregateId\":\"123\",\"AggregateType\":\"Typ\"}",
        "UserId": "userid",
        "CorrelationId": "correlation",
        "ContentVersion": "version2"
      },
      {
        "Id": "123",
        "Title": "Thing",
        "Updated": "2022-01-20T11:45:09.9243622+01:00",
        "Content": "{\"DocumentenID\":\"88c85db4-a02a-400f-9376-108acd146559\",\"ImportDatum\":\"2022-01-20T11:45:09.8859111+01:00\",\"AggregateId\":\"123\",\"AggregateType\":\"Typ\"}",
        "UserId": "userid",
        "CorrelationId": "correlation",
        "ContentVersion": "version2"
      }
    ]

We wanted to pact test that and obviously have issues with the nested json in the Content property. As this is our real contract, it would be very useful to test if this contract gets broken somehow. We thought that implementing a IMatcher would make this work, but the interface does not seem to handle some edgecase like that. I also thought of doing this in a regex but the thought of writing a regex for multiple objects just seems extremely laborious ^^ Is there a way to tell pact.net that he has to look into the string and check the json there? Or are there hooks in the library that we could use/abuse to make this possible? (I sadly guess a no)

The second issue that we will be having is, that the endpoint delivers different object in this Content property, as you can see… In the case that we could get rid of the string property and replace it with a proper object, would we be able to pact test that? My guess is that this is also not possible, but maybe I missed something.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
mefellowscommented, Jan 21, 2022

We’re aiming for plugins to be supported in Q1 this year. It requires the 4.x.x branch to be merged, and the plugin functionality added. So we’re likely a few months away I’d suggest.

0reactions
modmotocommented, Jan 21, 2022

Will those plugins arrive with 4.0 or somewhere later down the line?

Thanks for the info and the link so far. I will give it a look.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to identify if a JSON Object is nested or not
Iterate over the properties of the object. If any property value is an object, it's nested. – Felix Kling. Jul 13, 2015 at...
Read more >
Case Study: How To Parse Nested JSON
A common strategy is to flatten the original JSON by doing something very similar like we did here: pull out all nested objects...
Read more >
Storing and retrieving Nested JSON document
Step 1. Run Redis Docker container​ · Step 2. Verify if JSON feature is loaded​ · Step 3. Nested JSON​ · Step 4....
Read more >
Check if elements exists in Nested JSON
Hi All,. I am trying to check if element exists in Nested JSON object but it's not working. I have tried hasOwnProperty method...
Read more >
How to search in nested complex JSON - YouTube
... https://javascript.plainenglish.io/ how -to- search -in- nested - json - ... referralCode=6AF7AA3DB6AD6B880D66 React - The Complete Guide with ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found