-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBeispiele_json.py
More file actions
42 lines (35 loc) · 809 Bytes
/
Beispiele_json.py
File metadata and controls
42 lines (35 loc) · 809 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/local/bin/python3
##############################################
#
# Name: Beispiele_json.py
#
# Author: Peter Christen
#
# Version: 1.0
#
# Date: 10.11.2017
#
# Purpose: Beispiele mit Json
#
##############################################
import json
#Json2Python
jsonData = '{"name": "UM00365", "Nr.CPU": 4}'
pdict = json.loads(jsonData)
print ("#### Json2Python ####")
print (pdict)
print (pdict['name'])
#Python2Json
pdict = {'name': 'UM00365', 'Nr.CPU': 4}
jsonData = json.dumps(pdict)
print ("#### Python2Json ####")
print (jsonData)
#write Json-File
pdict = {'name': 'UM00365', 'Nr.CPU': 4}
with open('inventar.json', 'w') as outfile:
json.dump(pdict, outfile)
#read Json-File
pdict = json.load(open('inventar.json'))
print ("#### Read Json ####")
print (pdict)
print (pdict['name'])