Forum Discussion

dipsthorat's avatar
dipsthorat
Occasional Contributor
31 days ago

How to filter out data from json array

I have one API response  , where I need to filter out where "infrabelClassification" = 1, how and which assertion is useful ?

[
  {
    "id": 1,
    "commercialLongNameFrench": "Aachen Hbf (DE)",
    "infrabelClassification": 1
  },
  {
    "id": 2,
    "commercialLongNameFrench": "Aachen-Rothe-Erde",
      "infrabelClassification": 2
  },
  {
    "id": 3,
    "commercialLongNameFrench": "Aachen-Süd",
    "infrabelClassification": 1
  },
]

4 Replies

  • nmrao's avatar
    nmrao
    Champion Level 3

    Good you tried the script assertion.

    • Is that all that you need to verify from the response?
    • Or is there any particular data that needs to be verified?

    If you want to save the response for later use, it can be achieved in different ways based on the need. For ex:

    • save it in test case properties
    • serialize it to a file

    It would be better to understand how the data is going to be used for further?

    • to use whole or part of the response in next test request step  to get some data
    • use some values from response to get data
    • compare the response with verified data

    The more information available with the context, some one will be able to assist you.

  • dipsthorat's avatar
    dipsthorat
    Occasional Contributor

    I am able to achieve this using script assertion but that data is there in script assertion popup itself  but I want to use this data save somewhere or for my further testing

     

  • dipsthorat's avatar
    dipsthorat
    Occasional Contributor

    I need to filter out data from this json array where infrabelclassification = 1 and then used that filtered data data for my further testing