How do I remove data from a JSON object
This example demonstrates removing data from a JSON object.
In the solution shown below, the JSON object and JSON path are stored into the variables using "store" command. The "age" data is removed from the JSON object by providing its path using "jsonRemoveFromObject" command. The result is stored into a variable.
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 | {"insuranceDetails":{"age":45,"income": 25000,"zipcodeDetails": [{"zipcode": 90001,"state": "California"}]}} | JSON |
Store the JSON path in a variable | |||
2 | store |
$.insuranceDetails.age |
JSONPath |
Remove the data from the JSON object and store the result in a variable | |||
3 | jsonRemoveFromObject |
${JSON}||${JSONPath} |
Final_JSON |
Tips, Tricks, Gotchas & Best Practices:
- You can remove multiple data from the JSON object by providing the multiple JSON paths in the "Target" field separated by "," symbol.
- You can also call the JSON, JSON path and value directly in the "Target" field separated by "||" symbol in "jsonRemoveFromObject" command 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.