zohozoho-deluge

Converting JSONL response to collection/List in Zoho CRM Deluge


so I am trying to work with a 3rd party API which returns a JSONL response:

{"Key1":"Value1","Key2:Value2"}
{"Key1":"Value1","Key2:Value2"}
..so on

Now I want to convert this to a list of individual JSONs to process with for-each loop but I am unable to do so with in-built functions in Deluge.
Is there any way to do so?

I have tried toCollection("\n") and toJSONList() but both of them dont work. This mainly due to Deluge treating the response a contineous single string/text and hence no new lines in text.

I had expected it t return a list of JSONs:

[{"Key1":"Value1","Key2:Value2"},
{"Key1":"Value1","Key2:Value2"}]

Solution

  • Something like this may work.

    //----------------------------------------------------------------------    
    // Create a list by splitting on each JSON item's ending curly bracket.   
    // This removes the curly bracket so it will need to be added back later.     
    //----------------------------------------------------------------------       
    response_list = response_jsonl.toList("}");
    
    //----------------------------------------------------------------------    
    // Add back the curly-bracket removed in the split.   
    // Convert to Zoho Map and display keys.  This is just to verify it works.    
    // -  If it works change the code to do the desired action on the data.     
    //----------------------------------------------------------------------    
    for each item in response_list
    {
        item_json = item + "}";
        item_map = item_json.toMap();
        info item_map.keys();
    }