XML and JSON functions

XML and JSON functions

Difference between getJson and get

The major difference between getJson and get functions is the type of data on which the two functions work. The getJson function is meant to be performed on TEXT type which is in json or key-value format. The get function on the other hand can work on key-value collections and index-value collections. 

The getJSON function retrieves values from a JSON formatted text or a key-value collection using a key. The get function retrieves values from a key-value collection or an index-value collection using either an index or a key.

Syntax for getJson

  1. <variable> = <json_or_map_text>.getJson(<key>);

Syntax for get

  1. <variable> = <map_or_list>.get(<key_or_index>);
where,

Examples

1) The below example retrieves the ID of an employee from a JSON text. The backslashes are escape characters for quotation marks in the text, which tell the system that they are not to be considered as the standard beginning and ending quotations of the text.
  1.  employeeDetail = "{\"response\" : {\"employee\": {\"id\" : \"EMP-001\", \"role\" : \"Developer\"}}}";   
  2.  info employeeDetail.getJSON("response").getJSON("employee").getJSON("id");  // returns EMP-001
 
2) The below example retrieves the IDs of all employees in a form of a Collection from a JSON.
  1.  resp = {"data" : [{"Id":1, "firstname":"John", "lastName":"Day"},  {"Id":2, "firstname":"Patricia","lastname":"Boyle"}]}";
  2.  data = resp.getJson("data");
  3.  employeeList = data.toJSONList();
  4.  idList = Collection();
  5.  for each employee in employeeList
  6.  {
  7.    idList.insert(employee.getJson("Id"));
  8.  }
  9.  info idList;   //returns 1,2
 
3) The below example retrieves the values of the 'mobileID' key from all collections in the list.
  1. resp={"data":[{"Id":{"mobileID":1001,"laptopID":2002},"firstname":"John","lastName":"Day"},{"Id":{"mobileID":3003,"laptopID":4004},"firstname":"Patricia","lastname":"Boyle"}]};
  2.  data=resp.getJson("data");
  3.  employeeList=data.toJSONList();
  4.  idList=Collection();
  5.  for eachemployeeinemployeeList
  6.  {
  7.      idList.insert(employee.getJson("Id").get("mobileID"));
  8.  }
  9.  infoidList;   //returns 1001, 3003​​
 
4) The below example retrieves the values from a key-value collection based on the specified key.
  1. mapVar = {"Product":"Creator","Company":"Zoho"};
  2.  boolVal = mapVar.get("creator");   //returns null
  3.  newBoolVal=mapVar.get("Product");   //returns "Creator"
5) The below example retrieves an element based on the specified index.
  1. listVar={"Creator","CRM",{"Projects","Reports"}};
  2.  elementValue=listVar.get(2);   //returns {"Projects", "Reports"}
6) The below sample snippet is executed from Zoho Creator.  
  1. resp =zoho.crm.getRecords("Leads");
  2. It retrieves records from Zoho CRM in the following LIST format.
  3. {
  4.    "Owner":{
  5.       "name":"Dinesh",
  6.       "id":"4504261000000512001",
  7.       "email":"dinesh@zylker.com"
  8.    },
  9.    "Company":"Rangoni Of Florence",
  10.    "Email":"christopher-maclead@zylker.com",
  11.    "Description":null,
  12.    "$currency_symbol":"$",
  13.    "Rating":null,
  14.    "$review_process":{
  15.       "approve":false,
  16.       "reject":false,
  17.       "resubmit":false
  18.    },
  19.    "Website":"http://www.zylker.com",
  20.    "Twitter":"@zylker",
  21.    "Salutation":"Mr.",
  22.    "Last_Activity_Time":"2020-06-12T18:05:43+05:30",
  23.    "First_Name":"Christopher",
  24.    "Full_Name":"Mr. Christopher Maclead (Sample)",
  25.    "Lead_Status":"Lost Lead",
  26.    "Industry":"Service Provider",
  27.    "Record_Image":"b5be64b25cdb3bbca08d2e2ebd46390d2e00641ea87f7d5083a00acd8094cf3a2ed1da5eea5f2f355bdbd506ed82998e0ceb37fb40086177ec0aac5c1b5e6ebf2b8781a945c03a316fc094ba132f7666",
  28.    "Modified_By":{
  29.       "name":"Dinesh",
  30.       "id":"4504261000000512001",
  31.       "email":"dinesh@zylker.com"
  32.    },
  33.    "$review":null,
  34.    "$state":"save",
  35.    "Skype_ID":"christopher-maclead",
  36.    "$converted":false,
  37.    "$process_flow":false,
  38.    "Phone":"555-555-5555",
  39.    "Street":"375 St Rt",
  40.    "Zip_Code":"11953",
  41.    "id":"4504261000000200722",
  42.    "Email_Opt_Out":false,
  43.    "$approved":true,
  44.    "Designation":"VP Accounting",
  45.    "$approval":{
  46.       "delegate":false,
  47.       "approve":false,
  48.       "reject":false,
  49.       "resubmit":false
  50.    },
  51.    "Modified_Time":"2020-05-27T12:49:08+05:30",
  52.    "Created_Time":"2020-05-27T12:48:31+05:30",
  53.    "$converted_detail":{

  54.    },
  55.    "$editable":true,
  56.    "City":"Middle Island",
  57.    "No_of_Employees":null,
  58.    "Mobile":"555-555-5555",
  59.    "$orchestration":false,
  60.    "Last_Name":"Maclead (Sample)",
  61.    "$in_merge":false,
  62.    "State":"NY",
  63.    "Lead_Source":"Cold Call",
  64.    "Country":"United States",
  65.    "Tag":[

  66.    ],
  67.    "Created_By":{
  68.       "name":"Dinesh Dinesh",
  69.       "id":"4504261000000512001",
  70.       "email":"dinesh@zylker.com"
  71.    },
  72.    "Fax":null,
  73.    "Annual_Revenue":850000,
  74.    "Secondary_Email":null
  75. }

The above LIST is iterated and the get function is used to retrieve values from a nested collection.
  1. for each rec in resp 
  2.   {
  3.    info rec.get("Owner").get("name");
  4.   }

getJSON

The getJSON function retrieves values from a JSON formatted text or a key-value collection, using a key.

Return Type

The return type will depend on the data type of the returned value.

Syntax

  1. <variable>=<input>.getJson(<key>);
where,

Examples

The below example retrieves the ID of an employee from a JSON.
  1.  employeeDetail="{\"response\" : {\"employee\": {\"id\" : \"EMP-001\", \"role\" : \"Developer\"}}}";   
  2.  info employeeDetail.getJSON("response").getJSON("employee").getJSON("id");// returns EMP-001
The below example retrieves the IDs of all employees in a form of a Collection from a JSON.
  1. resp="{\"data\" : [{\"Id\":1, \"firstname\":\"John\", \"lastName\":\"Day\"},  {\"Id\":2, \"firstname\":\"Patricia\",\"lastname\":\"Boyle\"}]}";
  2. employeeList=resp.getJson("data");
  3.  idList=Collection();
  4.  for each employee in employeeList
  5.  {
  6.    idList.insert(employee.getJson("Id"));
  7.  }
  8.  info idList;//returns 1,2

toJSONList

The toJSONList function takes a text JSON array as an argument, and returns it as a list.

Return Type

LIST

Syntax

  1. <variable>=<json_text>.toJSONList();
where,

Examples

The example below retrieves a value inside Collection from a JSON.
  1.  json_text = "{Name:'Lia Shelton', OrderNo:[343,443,577]}";
  2.  orderNo = json_text.getJSON("OrderNo");
  3.  info orderNo.toJSONList(); // Returns 343,443,577
The example below retrieves IDs of all employees in the form of a Collection from a JSON.
  1.  response = "{\"data\" : [{\"id\":1, \"firstname\":\"John\", \"lastName\":\"Day\"},  {\"id\":2, \"firstname\":\"Patricia\",\"lastname\":\"Boyle\"}]}";
  2.  data=response.getJSON("data");
  3.  json_list = data.toJSONList();
  4.  id_list = List();
  5.  for each item in json_list
  6.  {
  7.     id_list.add(item.getJSON("id"));
  8.  }
  9.  info id_list;// Returns 1,2

toMap

The toMap function takes a JSON formatted text as an argument, and returns a key-value pair.

Return Type

KEY-VALUE

Syntax

  1. <variable>=<json_text>.toMap();
where,

Examples

  1.  products = "{company:Zoho, product:Creator}";
  2.  info products.toMap(); // Returns the key-value pair {"product":"Creator","company":"Zoho"}

toXML

The toXml function takes a JSON/MAP formatted text as an argument, and returns it as an XML.

Return Type

TEXT

Syntax

  1. <text>.toXml();
where,

Examples

  1.  jsonText="{Name:'Lia Shelton', OrderNo:[343,443,577]}";    
  2.  info jsonText.toXML(); /* returns the following XML
  3.  <root>
  4.  <OrderNo>343</OrderNo>
  5.  <OrderNo>443</OrderNo>
  6.  <OrderNo>577</OrderNo>
  7.  <Name>Lia Shelton</Name>
  8.  </root>
  9.  */

toXmlList

The toXmlList function takes an XML text, and returns the elements of the specified key or the specified xPath (using executeXpath) as a list.

Return Type

LIST

Syntax

  1. <variable>=<text>.toXmlList();
where,

Examples

  1.  xmlResponse=invokeurl
  2.  [
  3.      url:"https://www.w3schools.com/xml/cd_catalog.xml"
  4.      type:GET
  5.  ]; // gets an XML response
  6.  info xmlResponse.executexpath("/CATALOG/CD").toXmlList();// converts the elements in the given node into a list

    Zoho CRM Training Programs

    Learn how to use the best tools for sales force automation and better customer engagement from Zoho's implementation specialists.

    Zoho CRM Training
      Redefine the way you work
      with Zoho Workplace

        Zoho DataPrep Personalized Demo

        If you'd like a personalized walk-through of our data preparation tool, please request a demo and we'll be happy to show you how to get the best out of Zoho DataPrep.

        Zoho CRM Training

          Create, share, and deliver

          beautiful slides from anywhere.

          Get Started Now


            Zoho Sign now offers specialized one-on-one training for both administrators and developers.

            BOOK A SESSION








                                    You are currently viewing the help pages of Qntrl’s earlier version. Click here to view our latest version—Qntrl 3.0's help articles.




                                        Manage your brands on social media

                                          Zoho Desk Resources

                                          • Desk Community Learning Series


                                          • Digest


                                          • Functions


                                          • Meetups


                                          • Kbase


                                          • Resources


                                          • Glossary


                                          • Desk Marketplace


                                          • MVP Corner


                                          • Word of the Day


                                            Zoho Marketing Automation

                                              Zoho Sheet Resources

                                               

                                                  Zoho Forms Resources


                                                    Secure your business
                                                    communication with Zoho Mail


                                                    Mail on the move with
                                                    Zoho Mail mobile application

                                                      Stay on top of your schedule
                                                      at all times


                                                      Carry your calendar with you
                                                      Anytime, anywhere




                                                            Zoho Sign Resources

                                                              Sign, Paperless!

                                                              Sign and send business documents on the go!

                                                              Get Started Now




                                                                      Zoho TeamInbox Resources



                                                                              Zoho DataPrep Resources



                                                                                Zoho DataPrep Demo

                                                                                Get a personalized demo or POC

                                                                                REGISTER NOW


                                                                                  Design. Discuss. Deliver.

                                                                                  Create visually engaging stories with Zoho Show.

                                                                                  Get Started Now









                                                                                                      • Related Articles

                                                                                                      • Functions

                                                                                                        This guide helps you with the following: Create Functions  Normal Functions REST API Functions Invoke Functions  Edit Functions  Delete Functions Rest API Functions Authentication Version 2.0 Version 1.0 Example Comparison of Version 2.0 and 1.0 ...
                                                                                                      • Execute XML

                                                                                                        The executeXPath Deluge task executes an XPath in the context of the specified XML and returns the value as a string. Here, XPath refers to the XML Path Language for finding information in an XML document. XML documents can be represented as a tree ...
                                                                                                      • XML Manipulation - executeXpath

                                                                                                        This guide will help you with the following: Overview Syntax Return Type Examples Overview The executeXpath() function takes XML/JSON formatted text and XPath as arguments, and returns the values of the desired node from the text. Return Type TEXT ...
                                                                                                      • Built-in Functions

                                                                                                        This guide will help you with the following: String functions  Numeric Functions  Boolean string functions  Date Functions  Time functions  List Functions  Map Functions  XML Functions  URL Functions  Form Data Functions   A function is a set of ...
                                                                                                      • Custom Functions

                                                                                                        The guide will help you with the following: Create Custom Functions Program Custom Functions  Test Custom Functions  Associate with Workflow Rules  Manage Custom Functions  Custom functions help in automation where procedural logic is required, which ...
                                                                                                        Wherever you are is as good as
                                                                                                        your workplace

                                                                                                          Resources

                                                                                                          Videos

                                                                                                          Watch comprehensive videos on features and other important topics that will help you master Zoho CRM.



                                                                                                          eBooks

                                                                                                          Download free eBooks and access a range of topics to get deeper insight on successfully using Zoho CRM.



                                                                                                          Webinars

                                                                                                          Sign up for our webinars and learn the Zoho CRM basics, from customization to sales force automation and more.



                                                                                                          CRM Tips

                                                                                                          Make the most of Zoho CRM with these useful tips.



                                                                                                            Zoho Show Resources