Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Displaying the text file data in dictionary format [closed]

I have a text file(new.txt) which has data like:

{
    "String1": {
        "Value1": {"One":"a","Two":"b","Three":"c"},
        "Value2": {"One":"aa","Two":"bb","Three":"cc"},
         }

     "String2": {
         "Value1": {"One":"a1","Two":"b1","Three":"c1"},
         "Value2": {"One":"aa1","Two":"bb1","Three":"cc1"},
         }
}

I want to display the value of: String1,value1 that is {"One":"a","Two":"b","Three":"c"} String2,value2 and One that is "aa1"

How can i display it..

like image 556
Surya Gupta Avatar asked Dec 09 '25 00:12

Surya Gupta


1 Answers

import ast
with open('new.txt') as f:
    d = ast.literal_eval(f.read())
print d['String2']['Value2']['One']
like image 122
eumiro Avatar answered Dec 11 '25 12:12

eumiro