To create a Dictionary by using a CSV file?

Hi,

I know there was a similar question, but I didn't find the answer to my next question.

I would create a dictionary with the following JSON structure:
{ "En": { "KeyOne": "Value One", "KeyTwo": "Value Two" }, "Hu": { "KeyOne": "Első Érték", "KeyTwo": "Második Érték" }, "Sr": { "KeyOne": "Прва Вредност", "KeyTwo": "Друга Вредност" } }
Of course, the key-value pair seen in the Dictionary would have many more key-values ​​pairs.
So many key-values ​​pair would be in dictionary that creating a dictionary graphical would be difficult for me.

I would read the dictionary elements by 'list from csv table text' block from a CSV file, but I don't know what content CSV file could create the above-mentioned JSON structure?

Any advices will be appreciated!
Pál

This

but we probably need to see the csv data

Apparently, I did not ask clearly enough. I would not create a dictionary from a JSON file, but from a CSV file. The JSON file above is just an illustration of the structure of the dictionary to be created.

I would use one row per twig of the JSON tree, each items traces the path from the root to the twig, finally ending in the value:

"En", "KeyOne", "Value One"
"En", "KeyTwo", "Value Two"
"Hu", "KeyOne", "Első Érték"
"Hu", "KeyTwo", "Második Érték"
"Sr", "KeyOne", "Прва Вредност"
"Sr",  "KeyTwo", "Друга Вредност" 

Do you need code to convert this into a dictionary of dictionaries?

It would be wise to see if you can actually generate this csv table first.

1 Like

Yes, please provide the code that would generate a dictionary from the CSV file you have written.

The CSV file above can be easily created as a spreadsheet in LibreOffice Calc spreadsheet, for example; I would save the finished spreadsheet from Calc as a CSV file.

as requested:

image

This is from the csv twig table you supplied earlier.

csv_twig_bundle_to_dictionary (1).aia (4.5 KB)

sample.csv (207 Bytes)

I cheated and asked Google
https://www.google.com/search?q=algorithm+to+build+a+tree+from+a+list+of+its+twig+paths
and followed its result step by step, but had to tweak the end of each twig to avoid hanging empty dictionaries like fruit.

It's helpful in Google searches to know the graph theoretic terms tree, leaf, branch, twig, to find pre-existing solutions in other languages.

I had my fun, but I now expect you to find it more difficult than you expected to generate the csv input to this.