CSV Import field to Array - Is it possible?

Hi guys,

I would like to import CSV field as Array. Actually it is array because value is [{"#text":"Odstíny hnědé a béžové","@_xml:lang":"cze"},{"#text":"Shades of brown and beige","@_xml:lang":"eng"},{"#text":"Odcienie brązu i beżu","@_xml:lang":"lit"},{"#text":"Odcienie brązu i beżu","@_xml:lang":"pol"}] and if I copy this manually to Set Value step I got nice output:

Zrzut ekranu 2022-03-3 o 21.13.30

When I take the same value from the CSV Import step it is text so the output is text so it looks like this

Is there any option to get Array instead of text from CSV field or it is always text?
Another option is to get whole data from static JSON file but I couldn’t find solution for that either.

I hope I explained it clear and added in correct category.

What is the exact text stored in your CSV file?

The text you’ve included in your question is in JSON format, not CSV. This is why Wappler parses it an array with 4 objects as the JSON string is an array with 4 objects.

The equivalent text in CSV format is:

#text,@_xml:lang
Odstíny hnědé a béžové,cze
Shades of brown and beige,eng
Odcienie brązu i beżu,lit
Odcienie brązu i beżu,pol

image

image

Thanks for reply and explanation but it is more complicated.

You are right it is JSON format. Whole JSON is value of 1 field because my CSV file is translated from JSON. 1 line of CSV is 1 article which has a lot of specifications. one of the specifications is color description in 4 languages which is placed in 1 CSV field. I know that ideally it is to make something like this:

products.product.id,#text,@_xml:lang
1,Odstíny hnědé a béžové,cze
1,Shades of brown and beige,eng
1,Odcienie brązu i beżu,lit
1,Odcienie brązu i beżu,pol

but the problem is that each product will have more fields like this so one article will get a lot of lines what is not useful.

This is how it is now in CSV

products.product.id,products.product.description
1,"[{""#text"":""Odstíny hnědé a béžové"",""@_xml:lang"":""cze""},{""#text"":""Shades of brown and beige"",""@_xml:lang"":""eng""},{""#text"":""Odcienie brązu i beżu"",""@_xml:lang"":""lit""},{""#text"":""Odcienie brązu i beżu"",""@_xml:lang"":""pol""}]"

I hope I put more light on the issue :slight_smile:

You have a combination of CSV import and JSON decode

First, you import the CSV file, which will give you an array with an object of two fields:

  1. products.product.id
  2. products.product.description

The 2nd part, which is JSON decoding, I don’t have enough experience in Wappler to point you in the right direction without being sure, but it’s certainly possible.

I’d probably create a new empty Array, define the schema, and then repeat (iterate through) the old CSV array, and do a Set Value to push the $value (JSON decoded through a [custom] formatter on the Data Format/Data Binding Picker) to the new empty Array we’ve previously created