I am new to python and have tried to get data from a python json document , what I try to do is pass the information to python and json from python print a pdf with a table style. My code in json is
JavaScript
x
37
37
1
[
2
{
3
"files": 0,
4
"data": [
5
{"name": "RFC", "value": "XXXXXXX", "attId": 01},
6
{"name": "NOMBRE", "value": "JOSE", "attId": 02},
7
{"name": "APELLIDO PATERNO", "value": "MONTIEL", "attId": 03},
8
{"name": "APELLIDO MATERNO", "value": "MENDOZA", "attId": 04},
9
{"name": "FECHA NACIMIENTO", "value": "1989-02-04", "attId": 05}
10
],
11
"dirId": 1,
12
"docId": 4,
13
"structure": {
14
"name": "personales",
15
"folioId": 22
16
}
17
},
18
{
19
"files": 0,
20
"data": [
21
{"name": "CALLE", "value": "AMOR", "attId": 06},
22
{"name": "No. EXTERIOR", "value": "4", "attId": 07},
23
{"name": "No. INTERIOR", "value": "2", "attId": 08},
24
{"name": "C.P.", "value": "55060", "attId": 09},
25
{"name": "ENTIDAD", "value": "ESTADO DE MEXICO", "attId": 10},
26
{"name": "MUNICIPIO", "value": "ECATEPEC", "attId": 11},
27
{"name": "COLONIA", "value": "INDUSTRIAL", "attId": 12}
28
],
29
"dirId": 1,
30
"docId": 4,
31
"structure": {
32
"name": "direccion",
33
"folioId": 22
34
}
35
}
36
]
37
and in python i tip the next code
JavaScript
1
5
1
import json
2
f= open(prueba.json)
3
prueba = json.load(f)
4
prueba
5
print correctly content of json,but my idea is get only for example:
JavaScript
1
2
1
Nombre,Jose
2
and then use the parameters to build the table in pdf
I have tried the following
JavaScript
1
13
13
1
import json
2
json_data = []
3
with open('prueba.json') as json_file:
4
json_data = json.load(json_file)
5
for key, value in json_data.iteritems():
6
print key;
7
for item in value:
8
print item
9
for key, value in json_data.iteritems():
10
print key;
11
for item in value:
12
print item
13
But i have the next error:
JavaScript
1
2
1
AttributeError : 'list' object has no attribute 'iteritems'
2
I ‘m trying to do something for them but I must get each data of json
Advertisement
Answer
JavaScript
1
9
1
json_data = [] # your list with json objects (dicts)
2
3
with open('prueba.json') as json_file:
4
json_data = json.load(json_file)
5
6
for item in json_data:
7
for data_item in item['data']:
8
print data_item['name'], data_item['value']
9