Skip to content

How do I check for the occurrence of a specific value in a JSON

This example demonstrates how to check for the occurrence of a specific value in a JSON if a path argument is given, at a specific path within the object.

In the solution shown below, the occurrence of a specific value in the JSON is fetched using "jsonSearchValueOccurrence" command by providing JSON, value and path in the Target field. Returns "1" if the value is present in the path provided, else returns "0".

Note: The notation to reuse the value of the variable in Worksoft SaaS is ${<Variable Name>}.

Solution:

# Command Target Value
Store the JSON object in a variable
1 store { "age":45,"income":25000,"zipcodeDetails":[{ "zipcode":90001,"state": "California" }]} JSON
Get the occurrence of the age in JSON by providing path and store it in a variable
2 jsonSearchValueOccurrence
${JSON}||"45",$.age
occurrence

Tips, Tricks, Gotchas & Best Practices:  

  • You can also call JSON directly in the target field instead of storing them into a variable.
  • As a best practice, it is always advisable to define the variable names without any spaces and if you want to differentiate the words, use underscores.


Feedback and Knowledge Base