Enthusiast
Enthusiast

How to parse the JSON file in VCO workflow

Hi,


I am trying to write the workflow to parse the JSON files and retrieve the all keys and their values from JSON file but I could not find the appropriate APIs for the same. How we can write the workflow to parsing JSON file and retrieve values from file?


-AVR

5 Replies
VMware Employee
VMware Employee

Take a look at FileReader class in vCO API Explorer.

First you can use FileReader#readAll() to read the content of the file as string, and then use JSON.parse() to parse this content string and convert it to Javascript object.

0 Kudos
VMware Employee
VMware Employee

var javascriptObject = JSON.parse(jsonString);

var value = javascriptObject.key;

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you! Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator for vCenter Orchestrator tips and tutorials - @vCOTeam on Twitter
0 Kudos
Enthusiast
Enthusiast

Thanks buddy for your response, I already wrote the code  using JSON.parse(). I got confused how to handle different data types like “Array” that JSON contain and what should be the return from this utility workflow, property object that contains key value or something else that is useful for  other calling workflow. Basically I need some idea for this JSON parser utility workflow.

0 Kudos
VMware Employee
VMware Employee

Try with return type Any to see if it suits your use cases.

Also, consider implementing this utility not as a workflow but as a scripting action.

Enthusiast
Enthusiast

I have successfully written utility Action to parse the JSON file and return Properties object. Now I would like to create another utility action / workflow in vCO tp validate the input JSON file against JSON schema file, how we can write this any idea.

0 Kudos