A
A
Alex P.2017-01-15 03:56:07
Python
Alex P., 2017-01-15 03:56:07

How to import python object to JSON and vice versa?

class AAA:
    pass

a = AAA

task: to
correctly pack the object "a" into a json file.
I tried to convert the object to a string, but when unpacking it, I get a string back, but I would like to get a working object at the output ..
import json

j = str(AAA())
json_j = json.dumps(j, indent=4)

with open('file.json', 'w') as f:
    json.dump(j, f, indent=4)

with open("file.json", "r") as f:
    data_again = json.load(f)
    f.close()

Please advise what is wrong??

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
longclaps, 2017-01-15
@Big_Alex

Dig here .

I
Ilya Karavaev, 2017-07-12
@Quieteroks

And it doesn't have to be taken literally. At you through a template input and span is created. You can see them in your layout. And ul is already created after using some select2 with ajax loading.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question