Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parse Json in Zoho Creator

Tags:

json

getjson

zoho

I have a huge JSON which I need to parse in zoho creator and then upload that data into zoho reports.

JSON data:

{
    "response": {
        "result": {
            "SalesOrders": {
                "row": [
                    {
                        "no": "1",
                        "FL": [
                            {
                                "content": "15 Taco Bar - Fabio 5/12",
                                "val": "Subject"
                            },
                            {
                                "content": "Emily Fabio",
                                "val": "Contact Name"
                            },
                            {
                                "content": "Confirmed for Delivery",
                                "val": "Status"
                            },
                            {
                                "content": "Chaska Private Parties",
                                "val": "Account Name"
                            }
                        ]
                    }
                ]
            }
        },
        "uri": "/crm/private/json/SalesOrders/getRecords"
    }
}

jsonstring=jsondata.toString(); //convert json data to string
    resp1=remove(jsonstring,"{\"response\":{\"result\":{\"Potentials\":{\"row\":");//Formatted json
    list={"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "15"};       --This is list
    jsonmap = map();
    jsonmap=jsonstring.toMap(); //Convert json string to map
    jsonlist=jsonstring.toJSONList();                               
    address=jsonmap.get("Origin Address");
    info address;
    for each index j in list 
    {
        address = jsonstring.getJSON("Origin Address"); // get data from json.
        info address;   // print address
    }

It always show null return. Please help me to do this.

like image 559
Harish Chauhan Avatar asked Apr 10 '26 09:04

Harish Chauhan


1 Answers

you have 2 methods in Zoho Creator for parsing json

  • getJSON()

  • toJSONList()

both of this functions assume string as argument, but unlike Javascript you can specify only one (next) node in getJSON. here is example for parsing sales order:

response = jsondata.getJSON("response");
result = response .getJSON(" result");
SalesOrders =  result.getJSON("SalesOrders");
rows = SalesOrders.getJSON("row").toJSONList();
sales_order = Map();
// iterate Sales Orders
for each row in rows
{
      FL = row.getJSON("FL").toJSONList() ;
      // iterate parameters 
      for each f in FL
      {
            if (f.getJSON("val") != "products" )
            {
                  // put JSON Object in Map
                  sales_order.put(f.getJSON("val"),f.getJSON("content") );
            }
            else
            {
                  // products is JSON Array
                  items = f.getJSON("content").toJSONList();
                  // iterate product
                  .....
                  //
            }
      }
}

Hope it helps

like image 68
Igor Vatsenko Avatar answered Apr 11 '26 23:04

Igor Vatsenko



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!