Requesting a feature [Related to dictionaries](How to save/retrieve a dictionary from a File)

Is it possible to save a dictionary in a file and then retrieve the data back.

I know that in File component data is saved as text and read as text also. For list I can use ListToCSV and CSVToList to save and read through a file but for dictionary I dont know.

Please provide a method to do that

You can use the Web component for that. Use the method JsonObjectEncode to save the dictionary and JsonTextDecodeWithDictionaries to retrieve the json object

2 Likes

I will join this question because I have similar ones.
I have a text file in this form:

{"version":"1.0","type":"lcm/config","description":"","timestamp":"2019-12-29T17:13:19.149Z","configuration":{"3":"00002580","8":"02","11":"17D4","17":"0064","29":"01","31":"01","32":"00C8","34":"84","35":"0001","40":"83","41":"0001","64":"03","66":"32","68":"0096","69":"05","72":"46","73":"85","81":"00","84":"0383","85":"0391","99":"000A","100":"81","101":"0001","102":"00","114":"02BC","128":"01","129":"0BB8","130":"1388","132":"00","144":"01","145":"028A","146":"01","147":"0103","148":"0305","149":"0393","150":"0308","180":"01","181":"566F6C2E","288":"0096320F3206","289":"01F48788149603E80C80","304":"01","305":"0C","306":"05","307":"0F","308":"0B","309":"10","310":"0D","321":"DFFFFFFFFFFFFFFFFFFFFFFFFC00000080000000800000008000000080000001","336":"06","337":"14","338":"15","339":"03","340":"04","341":"05","342":"64","384":"8D0F200000","385":"0B00210000","386":"820A050000","387":"830A860001","388":"6102800002","389":"8A0F080000","390":"85030B0000","391":"84030C0000","392":"8603020000","393":"8703030000","394":"0801600000","396":"6103890001","416":"000043530502FFCC00005405023FFC0000010200530502FFCCFFCC5405023FE43FE4010100530502FFCC00005405023FFC0000010200530502FFCC00805405023FFC004000601F530502FFCC00005405023FFC0000010200540502000000005305020000000030530502FFCC02005405023FFC20000060530502FFCC20005405023FFC08000060530502FFCC08005405023FFC01000060530502FFCC00005405023FFC02000040530502FFCC04005405023FFC00800060530502FFCC10005405023FFC04000060530502FFCC01005405023FFC10000060530502FFCC00405405023FFC00200060530502FFCC01005405023FFC01000060530502FFCC10005405023FFC04000060530502FFCC04005405023FFC00800060530502FFCC00005405023FFC02000040530502FFCC08005405023FFC01000060530502FFCC20005405023FFC08000060530502FFCC02005405023FFC20000060530502FFCC00805405023FFC00400060","417":"0000FA550602FF00000000550603FF00000000550607FF00000000550608FF000000000096550603FF4400000055060422200000005506087F41000000003C550602FF09000000550603FF4C000000003C550602FF0D000000550607FF040000005506087F61000000003C550602FF1D0000005506087F69000000003C550603FF4D0000005506042222000000550607FF0C000000003C550602FF5D000000550607FF8C000000003C550607FF9C000000003C550603FF6D000000003C550603FFEF000000003C5506087F6F000000003C550607FFDC000000003C550602FFFD000000550603FFFF000000003C550607FFFF0000005506087F7F000000FA550603FFBB00000055060422020000005506087F3E000000003C550602FFF4000000550603FFB3000000003C550602FFF0000000550607FFFB0000005506087F1E000000003C550602FFE00000005506087F16000000003C550603FFB20000005506042200000000550607FFF3000000003C550602FFA0000000550607FF73000000003C550607FF63000000003C550603FF92000000003C550603FF10000000003C5506087F10000000003C550607FF23000000003C550602FF00000000550603FF00000000003C5506080000000000550607FF0000000000965506020000000000550603000000000055060400000000005506070000000000010064","418":"00000F530502C000C00055060280800000000F53050200000000550602000000000002530502C000C0005506028080000000","419":"0000123002580504AE0108083002590504AE0108080000","420":"0000123002580504AE0108003002590504AE0108000000","421":"00000311010F0311050000","422":"0000095405020080008000FF07540502000000000E5405020100010000FF5405020080008000FF5405020100010000FF5405020000000000FF5405020180018000FF5405020000000000FF5405020180018000FF","423":"000009300275053C071E02FF0000","424":"000009300275053C071E01FF0000","425":"0000000E5305020000000054050200000000772F02530502FFCC03005405023FF401800064530502FFCC0000E905AE1503FFFF5405023FF400600064890415030000530502FFCC30005405023FF430000064530502FFCC000C5405023FF40C000064530502FFCC03005405023FF401800064530502FFCC000089041503FFFF5405023FF400600064890415030000530502FFCC30005405023FF430000064530502FFCC000C5405023FF40C000064530502FFCC00005405023FF400000064530502FFCC00C05405023FF401800064530502FFCC00CC5405023FF40D800064530502FFCC0CCC5405023FF40DE00064530502FFCC3CCC5405023FF43DE00064530502FFCC3CCC89041503FFFF5405023FF43DE40064530502FFCC3FCC5405023FF43FE400C8530502FFCC00008904150300005405023FF4000000645405023FF4294000C85405023FF43DE000C85405023FF43DE0530502FFCC154489041501FF0000C85405023FF43DE0530502FFCC3FCC89041503FFFF00C8530502FFCC00008904150300005405023FF400000064530502FFCC3FCC89041503FFFF5405023FF43FE40032530502FFCC00008904150300005405023FF400000032530502FFCC3FCC89041503FFFF5405023FF43FE40032530502FFCC00008904150300005405023FF400000032530502FFCC3FCC89041503FFFF5405023FF43FE40032530502FFCC00008904150300005405023FF400000032530502FFCC3FCC89041503FFFF5405023FF43FE40032530502FFCC00008904150300005405023FF400000032530502FFCC3FCC89041503FFFF5405023FF43FE40032530502FFCC00008904150300005405023FF400000032530502FFCC3FCC89041503FFFF5405023FF43FE40032530502FFCC00008904150300005405023FF400000032","426":"0000031501120313150000","464":"416E696D61636A612070727A6F64202B2074796C","465":"416E696D206B6F6E74726F6C656B","466":"4D696A616E6961202B206B6F6E74726C6B612064726F676F77796368","467":"5AC582C3B3C5BC206C7573747261","468":"526F7AC582C3B3C5BC206C7573747261","469":"536369737A616E696520646F203135","470":"506F647A69C4996B6F77616E6965","471":"626565702062656570","472":"62656570","473":"42616C616E6761","474":"566964656F","563":"03E8","565":"01","576":"82","577":"01","578":"01","582":"8A","583":"0064","586":"B0","591":"BEBF2D012C280701F4","752":"01","768":"01","769":"04","770":"1C","771":"21","774":"07","775":"08","776":"09","777":"0A","778":"0B","779":"0C","780":"0D","781":"0E","782":"0F","783":"10","784":"11","785":"12","786":"13","787":"14","788":"1C","789":"1E","790":"1F","791":"20","792":"21","793":"22","794":"23","795":"2C","796":"2D","797":"2F","798":"30","799":"31","800":"32","801":"33","802":"41","803":"43","832":"02","833":"01","834":"60","835":"61","836":"62","837":"63","838":"80","839":"83","840":"85","841":"86","842":"92","843":"93","844":"8A","845":"8B","846":"8C","847":"8D","848":"8E","849":"91","850":"95","851":"96","852":"98","853":"99","854":"93","855":"92","856":"A0","857":"A4","858":"A8","859":"AC","860":"A1","861":"A5","862":"A9","863":"AD","864":"6C","865":"06","866":"07","867":"08","1008":"00","1018":"000252065205520102030405060708090A0B0C","1019":"000258065805580102030405060708090A0B0C","1020":"000259065905590102030405060708090A0B0C","1021":"000255065505550102030405060708090A0B0C","1023":"4D56FA9268146F2D21029E28B2BE588597D1939B2E86F7DAF038A2A80F3B286170BE994E655FF60803238FC3E3E78FECEC1B2603C86A8F"}}

Is it possible to enter such content directly to the dictionary in this way:
blocks (28)

It doesn’t work for me. Displays “not found”.

First check that all double quotes are correct " replace any slanted ones with the vertical one.

Then try this with blocks, you will need the web component. I have used two dictionary blocks to get to the inner list. (there is a better way)

Could you explain why the web component is necessary? When I do the opposite, that is, the content of the dictionary I send to the text field, I get the text in the same form as mine.

image

Works with the web component.
I did this test:
“global konfiguracja” is a dictionary.
blocks (29)

I received this text:
90692372_285634492406819_5408938193170989056_n

So if I want to send json from the dictionary to the file I can do it directly, while the other way round from file json to the dictionary via the web component?

I think that’s a historical consideration. JSON and dictionaries were originally too high level a concept for the AI2 target educational audience. Then Web users started encountering JSON, so the decoding facility started there. Then people started accessing the decoded JSON as lists of pairs, so the next step was dictionaries.

AI2 functionality dribbles out slowly, depending on the supplied of unpaid labor (grad students, friendly competitors.)

The opinions in this post are entirely mine, and not necessarily of MIT or of AI2’s people.

I would like to clarify that we do pay students (both undergraduate and graduate students), although during the semester they are capped at no more than 10 hours per week by MIT policy. Students tend to work on more exploratory research projects that the development team then polishes up. Of course, anyone who knows Java, JavaScript, or Android development is welcome to contribute patches via GitHub.

I noticed that the web component does not leave the dictionary in its original state. The dictionary is sorted. It is not sorted like this: 1, 2, 10, 30, 100, only this way: 1, 10, 100, 2, 30.

Because they are text, not numbers.

Second problem. I have one value “lcm / config”. After conversion, the value looks like this: “lcm \ / config”.

And what is the difference between numbers and text in ai2? This is not a problem with numbers or text, but sorting which is not needed.

The system has to “escape” the forward slash with a backslash. You will need a little text replacement result procedure to remove the backslashes

The raw json data is a string (text) and all values are in quotes. This makes any “number values” text and not a number. If you want to sort these you can use a leading zeros procedure so that, for example, 1,100, 2 becomes 0001,0002,0100. You can still use these as numbers in maths operations in AI2.

Earlier I asked the question why a web component is needed. Language is a problem here. I meant that my data before conversion looks the same as after conversion. "key":"value". So what changes conversion except sorting and replacing "/" on "\ /".

Or otherwise. What needs to be changed in the json file like above I pasted so that it would be read correctly by the dictionary. I would like to convert the file myself without the web component.

I discarded / but it still doesn’t work without the web component.