Sun Jul 03, 2022 7:56 am
Login Register Lost Password? Contact Us

Please Note: The HPCC Systems forums are moving to Stack Overflow. We invite you to post your questions on Stack Overflow utilizing the tag hpcc-ecl (https://stackoverflow.com/search?tab=newest&q=hpcc-ecl). This legacy forum will be active and monitored during our transition to Stack Overflow but will become read only beginning September 1, 2022.



JSON arrays

Comments and questions related to the Enterprise Control Language

Mon Jan 17, 2022 5:16 pm Change Time Zone

I'm trying to read the following JSON:
Code: Select all
{
   "level1_field1":[
      "level1_value1",
      "level2_value2"
   ]
}


The ECL record structure I would think I need is:
Code: Select all
ResultData := RECORD
  SET OF UTF8 level1_field1;
END;


However if I try parsing that using FROMJSON I get my record contains a level1_field1 which in turn appears to contain a record named Item and which contains no data (
parsed_json_empty.png
(3.84 KiB) Not downloaded yet
). Does anyone know a way round this or do I need to create a JIRA?
james.wilson
 
Posts: 25
Joined: Fri Nov 14, 2014 3:44 pm

Tue Jan 18, 2022 10:22 am Change Time Zone

Aha! A colleague has helped me out with this, it works correctly if the field has an XPATH:
Code: Select all
ResultData := RECORD
  SET OF UTF8 level1_field1 {XPATH('level1_field1')};
END;


So TL;DR is always, always have XPATHs for all fields when parsing JSON (which will also get round annoying case issues as if there's no XPATH then HPCC will use a lowercased version of the field name).
james.wilson
 
Posts: 25
Joined: Fri Nov 14, 2014 3:44 pm


Return to ECL

Who is online

Users browsing this forum: No registered users and 1 guest

cron