Skip to content

How do I retrieve an object from JSON using "index" as a reference

This example demonstrates retrieving an object from a JSON document by providing the index using the "jsonStoreObjectByIndex" command.

In the solution shown below, the JSON object is stored into the variable using the "store" command, and then the object is retrieved from the JSON document by index using the "jsonStoreObjectByIndex" command.

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 [{"zipcode":90001,"state": "California"},{"zipcode":10001,"state": "New York"},{"zipcode":08817,"state": "New Jersey"},{"zipcode":15201,"state": "Pennsylvania"}] JSON
Store the index of the object to be retrieved
2 jsonStoreObjectByIndex
${JSON} || 3
Json_Object

Tips, Tricks, Gotchas & Best Practices:  

  • You can call the JSON directly in the "Target" field in the "jsonStoreObjectByIndex" command instead of storing it 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