回答編集履歴

1

jsonのサンプルと、pythonのソースを追加しました。

2019/06/04 06:56

投稿

waku_nagoya
waku_nagoya

スコア200

test CHANGED
@@ -1,3 +1,189 @@
1
1
  その json データでは、 issues キーが重複するため、どんどん上書きされていって最後の issues のみ残ってしまいます。
2
2
 
3
3
  そこを改良してください。
4
+
5
+
6
+
7
+ ここから追記です。
8
+
9
+
10
+
11
+ filename : tera.json
12
+
13
+ ```json
14
+
15
+ {
16
+
17
+ "expand": "schemanames",
18
+
19
+ "startAt": 0,
20
+
21
+ "maxResults": 100,
22
+
23
+ "total": 150,
24
+
25
+ "issues": [
26
+
27
+ {
28
+
29
+ "expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields",
30
+
31
+ "id": "111111",
32
+
33
+ "self": "https://sample.jp//api/2/project/111111&#039",
34
+
35
+ "key": "911",
36
+
37
+ "fields": {
38
+
39
+ "parent": {
40
+
41
+ "id": "54321",
42
+
43
+ "key": "11",
44
+
45
+ "self": "https://sample.jp//api/2/project/11112&#039"
46
+
47
+ }
48
+
49
+ }
50
+
51
+ },
52
+
53
+ {
54
+
55
+ "expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields",
56
+
57
+ "id": "111112",
58
+
59
+ "self": "https://sample.jp//api/2/project/111111&#039",
60
+
61
+ "key": "912",
62
+
63
+ "fields": {
64
+
65
+ "parent": {
66
+
67
+ "id": "54322",
68
+
69
+ "key": "12",
70
+
71
+ "self": "https://sample.jp//api/2/project/11112&#039"
72
+
73
+ }
74
+
75
+ }
76
+
77
+ }
78
+
79
+ ],
80
+
81
+ "issues2": [
82
+
83
+ {
84
+
85
+ "expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields",
86
+
87
+ "id": "222222",
88
+
89
+ "self": "https://sample.jp//api/2/project/222222&#039",
90
+
91
+ "key": "912",
92
+
93
+ "fields": {
94
+
95
+ "parent": {
96
+
97
+ "id": "64320",
98
+
99
+ "key": "21",
100
+
101
+ "self": "https://sample.jp//api/2/project/11142&#039"
102
+
103
+ }
104
+
105
+ }
106
+
107
+ },
108
+
109
+ {
110
+
111
+ "expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields",
112
+
113
+ "id": "3333",
114
+
115
+ "self": "https://sample.jp//api/2/project/222222&#039",
116
+
117
+ "key": "913",
118
+
119
+ "fields": {
120
+
121
+ "parent": {
122
+
123
+ "id": "54321",
124
+
125
+ "key": "22",
126
+
127
+ "self": "https://sample.jp//api/2/project/11142&#039"
128
+
129
+ }
130
+
131
+ }
132
+
133
+ }
134
+
135
+
136
+
137
+ ]
138
+
139
+ }
140
+
141
+
142
+
143
+ ```
144
+
145
+
146
+
147
+ こんな構造のjsonだったとしたら
148
+
149
+
150
+
151
+ ```python
152
+
153
+ import pandas as pd
154
+
155
+ from pandas.io.json import json_normalize
156
+
157
+ import openpyxl
158
+
159
+
160
+
161
+ f= open("tera.json", "r")
162
+
163
+ data = json.load(f)
164
+
165
+
166
+
167
+ with pd.ExcelWriter("test.xlsx") as writer:
168
+
169
+ for v in data:
170
+
171
+ if "issues" in v:
172
+
173
+ r = json_normalize(data[v])
174
+
175
+ r.to_excel(writer, sheet_name=v)
176
+
177
+ ```
178
+
179
+
180
+
181
+ これで大体やりたいことはできるかと思います。
182
+
183
+
184
+
185
+ jsonを修正したところとしては、issues のキー名を重複しないように変更したことです。
186
+
187
+ もっと構造を変えてもよければ、issues自体をリスト化することです。
188
+
189
+ そうするともう少しスマートになるかと。