Thu Aug 18, 2022 8:05 pm
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.



Parse a JSON field where the name starts with a number?

Comments and questions related to the Enterprise Control Language

Thu Jan 13, 2022 10:52 am Change Time Zone

I have some JSON that looks like this:

{
  "first_field": "a value",
  "2nd_field": "another value"
}

Is it possible to model this in ECL? I can't have a fieldname that starts with a number

MyLayout := RECORD
STRING first_field;
STRING 2nd_field;
END;


But I don't appear to be able to do it with XPATH either, this produces a compilation error too:

MyLayout := RECORD
STRING first_field;
STRING second_field {XPATH('2nd_field')};
END;


Any ways round this?
james.wilson
 
Posts: 25
Joined: Fri Nov 14, 2014 3:44 pm

Thu Jan 13, 2022 7:50 pm Change Time Zone

James,

Yep, looks like the XPATH parser doesn't like names that start with a number. :(

My only suggestion is to edit the source JSON text and search/replace all those names by prepending an underscore (i.e. change "2field" to "_2field") and then the parser will be happy.

Otherwise, if this is a common practice in JSON, you need to submit a JIRA to fix the "bug" in the parser.

HTH,

Richard
rtaylor
Community Advisory Board Member
Community Advisory Board Member
 
Posts: 1619
Joined: Wed Oct 26, 2011 7:40 pm

Fri Jan 14, 2022 11:31 am Change Time Zone

Hi Richard

Unfortunately it's not my JSON so I can't change the field names :(

I've created https://track.hpccsystems.com/browse/HPCC-26969 to see if it can be fixed at some point.

Thanks

James
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