Sun Oct 13, 2019 10:24 pm
Login Register Lost Password? Contact Us


FROMJSON to DataSet

Comments and questions related to the Enterprise Control Language

Thu May 09, 2019 7:02 pm Change Time Zone

How can I turn the json array into a child dataset verses a SET?

Code: Select all
x := '{"childNames": ["Sasha Obama","Malia Obama"]}';

PersonRec := RECORD
   DATASET({UNICODE name}) childNames {xpath('childNames')};
END;

line := FROMJSON(PersonRec,x);

line;
wjblack
 
Posts: 27
Joined: Mon Jul 11, 2016 12:45 pm

Mon May 13, 2019 3:19 pm Change Time Zone

Hi wjblack,

Divide and conquer:
Code: Select all
x := '{"childNames": [{"FN" : "Sasha"},{"FN":"Malia"}]}';

PERSONRec := RECORD
   STRING FN{xpath('FN')};
END;

PeopleRec := RECORD
   DATASET(PERSONRec) childNames {xpath('childNames')};
END;

FROMJSON(PeopleRec,x);


Yours
Allan
Allan
 
Posts: 375
Joined: Sat Oct 01, 2011 7:26 pm

Mon May 13, 2019 3:41 pm Change Time Zone

In addition, I always find it worth my while to search the Forum on say 'JSON'.
There are other posts that might have helped.

Yours
Allan
Allan
 
Posts: 375
Joined: Sat Oct 01, 2011 7:26 pm

Mon May 13, 2019 7:41 pm Change Time Zone

Thanks for your help. I always do start with a search of the forum.
wjblack
 
Posts: 27
Joined: Mon Jul 11, 2016 12:45 pm

Thu Oct 10, 2019 3:01 pm Change Time Zone

What about if there's a attribute that one service has that's optional? For example, what if ServiceA has a member named 'ServiceAFlag' that's not always present for Service A and there's no concept of that for Service B. How will the record structure look then? If we specify 'ServiceAFlag' in the record structure and it's not in the json it seems to pull in one of the known fields.

Code: Select all
{
   "text": "Hello World",
   "services": [
      {
         "name": "ServiceA",
         "body": "default",
         "ServiceAFlag": "value",
      },
      {
         "name": "ServiceB",
         "body": "custom"
      }
   ]
}


Code: Select all
ServiceRec := RECORD
  UNICODE name{xpath('name')};
  UNICODE body{xpath('body')};
  UNICODE ServiceAFlag{xpath('ServiceAFlag')};
END;
RequestRec := record
  UNICODE text{xpath('text')};
  DATASET(ServiceRec) services {xpath('services')}
end;
wjblack
 
Posts: 27
Joined: Mon Jul 11, 2016 12:45 pm


Return to ECL

Who is online

Users browsing this forum: No registered users and 0 guests

cron