LAE

Welcome to the LAE community!  Please feel free to start a discussion in the discussion tab or join in a conversation.

Discussions

Members

Resources

Events

 View Only
  • 1.  JSON Data where fields include arrays

    Employee
    Posted 12-01-2015 05:24

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: mlam

    Hi guys,

    Is there a way to configure the JSON Data node to read in an array as a single string instead of splitting into separate records?

    For example, let's say I have the following 1 record - the field ingredient contains an array of 3 values:
    {
    "meal":"Dinner",
    "ingredients":["potatoes","carrots","peas"],
    "cooking_time":"30 minutes"
    }


    When this is parsed through the JSON data node, the output contains 3 rows, where each row contains each value in the ingredients array and the value for meal and cooking_time are repeated:

    ingredient cooking_time meal
    potatoes 30 minutes Dinner
    carrots 30 minutes Dinner
    peas 30 minutes Dinner

    But I want the output to be a single record, with ingredient array values as a single string:

    ingredient cooking_time meal
    potatoes,carrots,peas 30 minutes Dinner

    Is there a way to configure this within the node? I can manage this alternative ways using BRIANscript etc but I'm hoping there's a parameter setting in the node that I've missed.

    Thanks,
    Michelle


  • 2.  RE: JSON Data where fields include arrays

    Employee
    Posted 12-04-2015 07:53

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: mlam

    Following from above...

    There isn't a way to do this within the node in the way that I was thinking, but there are ways around it, including:

    1. Output array field to separate output pin
    2. Read data as per JSON Data node and aggregate results
    3. Read data as delimited text and manipulate JSON data record to exclude array field

    1. Output array field to separate output pin
    In the JSON Data node, you can add additional outputs for specific attributes such that the data values for those attributes are output to a separate pin than the catch-all "Data" output. This is detailed in the help for the JSON data node.
    Note: At present, this will only work if the attribute specified is not the top level attribute i.e. if I have {"sample": ["a":"1","b":"2","c":"3"] } then I can pull out "sample.c" but if I had {["a":"1","b":"2","c":"3"] }, I wouldn't be able to specify "c".

    2. Read data as per JSON Data node and aggregate results.
    Read in data as per JSON Data node then collapse the multiple lines to single record using Agg node.

    3. Read data as delimited text and manipulate JSON data record to exclude array field.
    Read the JSON data in as delimited text, strip out the array element and recreate JSON data string without array value, parse through JSON node to format fields then add array column back in after.