I have a column with multiple arrays and I’m trying to split out the elements, but they don’t have names, do I need to define each one? I’ve tried multiple things but nothing seems to work. I found another post with similar issue and tried the most recent solution pasted below.
The column with the arrays I’m trying to parse is called csv which you can see in the workflow.
Current workflow returns the following error;
Problem executing workflow
There was a problem executing the workflow: “Unexpected token u in JSON at position 0 [Line 4]”
I copied the code in the function from another post, so maybe it’s not what I should be doing here?
Specifically what I need solved is that I have an multi-level array that looks something like this;
Each array means something, which I can define from the source, and each of those elements in the array also has a meaning which I can also define, but maybe I have to assign that definitions when I parse this out?
So the output of the above would be 4 columns. First column would have the first element of the first array. Then 2nd column would have the 2nd element of the first array. 3rd column would have 3 values, it would be each of the 7 digit numbers from the 2nd array, 4th column would be the 2nd value of each pairing. Hopefully that makes sense.
This has gotten be closer by being able to use the set node, but the issue is still that it’s looking at each element as a different field. What I mean by that is this,… that first array, 0,0 and 0,1. fine no issues separate the two values into that first row. But then in the second array each of those 7 digit numbers is actually a funky way of providing the Unix Epoch time, I’ll actually have to do some additional manipulating after I figure this part out,… but all those values are the same definition within that array, same with the 4 digit numbers in that array they are all the same,… they are actually “price”,… how do I define each pairing so essentially each array should just give me two columns of data, “Date” & “Price”.
You did help my split out the arrays though so that at least for now I can work within a single array to try and define the elements within that array.
This is what I have so far based on your suggestion where I was able to now isolate the 2nd array;
Hm, I am not sure I fully understand. Could you perhaps share the full JSON you currently have (feel free to redact the actual values, I am just interested in the data structure) and the JSON data you would like to see instead?
Hi @JasonA, this seems to be invalid JSON which makes it really hard to know whether I am on the right track. This is in addition to the other problems: Can there be multiple products items or just one? Same with csv. I just have no idea how exactly this format works. So, this isn’t exactly about splitting an array but mostly guesswork instead.
Purely based on the snippet you have you have provided and with a bit of guessing as to how the JSON structure continues, I think code like this could do the job:
This will convert the part highlighted below into a field of its own:
Does this no longer work with the code node? Looks like most recent versions code node replaced function item, but I see in the docs looks like maybe impacted this to work using code? below is my modified version of what you provided above.
I’m getting this error
ERROR: item is not defined. Did you mean $input.item.json? [line 12, for item 0]
Note, this exact code works on previous version using function item. And I don’t know how to provide sample data here because this only allows me to upload an image file.