“Импорт JSON в Python” Ответ

Python Import json в Pymongo

import json
from pymongo import MongoClient

client = MongoClient('localhost', 27017)
db = client['countries_db']
collection_currency = db['currency']

with open('currencies.json') as f:
    file_data = json.load(f)

# if pymongo < 3.0, use insert()
collection_currency.insert(file_data)
# if pymongo >= 3.0 use insert_one() for inserting one document
collection_currency.insert_one(file_data)
# if pymongo >= 3.0 use insert_many() for inserting many documents
collection_currency.insert_many(file_data)

client.close()
Fragile Gecko

Python json String to Object

import json

x =  '{ "name":"John", "age":30, "city":"New York"}'
y = json.loads(x)

print(y["age"]) 
Anxious Ant

JSON LOAD FROM FILE Python 3

import json

with open('file_to_load.json', 'r') as file:
  data = json.load(file)
The Nic

Python Json Stringify

import json

json.dumps(['foo', {'bar': ('baz', None, 1.0, 2)}])
'["foo", {"bar": ["baz", null, 1.0, 2]}]'

print(json.dumps({"c": 0, "b": 0, "a": 0}, sort_keys=True))
{"a": 0, "b": 0, "c": 0}
Coder Cuttlefish

JSON в Python

import json

json_file = json.load(open("your file.json", "r", encoding="utf-8"))

# For see if you don't have error:
print(json_file)
Grieving Gull

Импорт JSON в Python

# For reading JSON file we import json module
import json
Unsightly Unicorn

Ответы похожие на “Импорт JSON в Python”

Вопросы похожие на “Импорт JSON в Python”

Больше похожих ответов на “Импорт JSON в Python” по Python

Смотреть популярные ответы по языку

Смотреть другие языки программирования