A
A
andrey_levushkin2021-05-12 14:48:00
In contact with
andrey_levushkin, 2021-05-12 14:48:00

Why does the JSON view disappear when writing to a file?

There is such a line (an array from JSON, already converted by json.dumps): I'm trying to write it to a file
test = [{"a": 1, "b": 2}, {"c": 3, "d": 4}]

with open(path, 'w') as fw:
    fw.write(result)


But in the end, the contents of the file are:
[{'a': 1, 'b': 2}, {'c': 3, 'd': 4}]
(all double quotes were replaced by single ones)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
iBird Rose, 2018-11-09
@iiiBird

it depends on the type of application. I won’t tell you everything, but for example, if the application type is "embedded application" - "application" or "game", then they do not have support for the mobile version.
and for example, the community application has a mobile version of the
type "VK Apps" also has a mobile version

S
Sergey Karbivnichy, 2021-05-12
@andrey_levushkin

You need to use json.dump:

import json
test = [{"a": 1, "b": 2}, {"c": 3, "d": 4}]

with open('test.json', 'w') as file:
    json.dump(test, file)

test.json:
[{"a": 1, "b": 2}, {"c": 3, "d": 4}]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question