Skip to content

Commit abe1327

Browse files
committed
Created Script To Convert XML To JSON
1 parent cb73efa commit abe1327

3 files changed

Lines changed: 248 additions & 0 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import json
2+
import xmltodict
3+
4+
with open('input.xml') as xml_file:
5+
parsed_data = xmltodict.parse(xml_file.read())
6+
7+
xml_file.close()
8+
9+
json_conversion = json.dumps(parsed_data)
10+
11+
with open('output.json', 'w') as json_file:
12+
json_file.write(json_conversion)
13+
14+
json_file.close()
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
<?xml version="1.0"?>
2+
<catalog>
3+
<book id="bk101">
4+
<author>Gambardella, Matthew</author>
5+
<title>XML Developer's Guide</title>
6+
<genre>Computer</genre>
7+
<price>44.95</price>
8+
<publish_date>2000-10-01</publish_date>
9+
<description>An in-depth look at creating applications
10+
with XML.</description>
11+
</book>
12+
<book id="bk102">
13+
<author>Ralls, Kim</author>
14+
<title>Midnight Rain</title>
15+
<genre>Fantasy</genre>
16+
<price>5.95</price>
17+
<publish_date>2000-12-16</publish_date>
18+
<description>A former architect battles corporate zombies,
19+
an evil sorceress, and her own childhood to become queen
20+
of the world.</description>
21+
</book>
22+
<book id="bk103">
23+
<author>Corets, Eva</author>
24+
<title>Maeve Ascendant</title>
25+
<genre>Fantasy</genre>
26+
<price>5.95</price>
27+
<publish_date>2000-11-17</publish_date>
28+
<description>After the collapse of a nanotechnology
29+
society in England, the young survivors lay the
30+
foundation for a new society.</description>
31+
</book>
32+
<book id="bk104">
33+
<author>Corets, Eva</author>
34+
<title>Oberon's Legacy</title>
35+
<genre>Fantasy</genre>
36+
<price>5.95</price>
37+
<publish_date>2001-03-10</publish_date>
38+
<description>In post-apocalypse England, the mysterious
39+
agent known only as Oberon helps to create a new life
40+
for the inhabitants of London. Sequel to Maeve
41+
Ascendant.</description>
42+
</book>
43+
<book id="bk105">
44+
<author>Corets, Eva</author>
45+
<title>The Sundered Grail</title>
46+
<genre>Fantasy</genre>
47+
<price>5.95</price>
48+
<publish_date>2001-09-10</publish_date>
49+
<description>The two daughters of Maeve, half-sisters,
50+
battle one another for control of England. Sequel to
51+
Oberon's Legacy.</description>
52+
</book>
53+
<book id="bk106">
54+
<author>Randall, Cynthia</author>
55+
<title>Lover Birds</title>
56+
<genre>Romance</genre>
57+
<price>4.95</price>
58+
<publish_date>2000-09-02</publish_date>
59+
<description>When Carla meets Paul at an ornithology
60+
conference, tempers fly as feathers get ruffled.</description>
61+
</book>
62+
<book id="bk107">
63+
<author>Thurman, Paula</author>
64+
<title>Splish Splash</title>
65+
<genre>Romance</genre>
66+
<price>4.95</price>
67+
<publish_date>2000-11-02</publish_date>
68+
<description>A deep sea diver finds true love twenty
69+
thousand leagues beneath the sea.</description>
70+
</book>
71+
<book id="bk108">
72+
<author>Knorr, Stefan</author>
73+
<title>Creepy Crawlies</title>
74+
<genre>Horror</genre>
75+
<price>4.95</price>
76+
<publish_date>2000-12-06</publish_date>
77+
<description>An anthology of horror stories about roaches,
78+
centipedes, scorpions and other insects.</description>
79+
</book>
80+
<book id="bk109">
81+
<author>Kress, Peter</author>
82+
<title>Paradox Lost</title>
83+
<genre>Science Fiction</genre>
84+
<price>6.95</price>
85+
<publish_date>2000-11-02</publish_date>
86+
<description>After an inadvertant trip through a Heisenberg
87+
Uncertainty Device, James Salway discovers the problems
88+
of being quantum.</description>
89+
</book>
90+
<book id="bk110">
91+
<author>O'Brien, Tim</author>
92+
<title>Microsoft .NET: The Programming Bible</title>
93+
<genre>Computer</genre>
94+
<price>36.95</price>
95+
<publish_date>2000-12-09</publish_date>
96+
<description>Microsoft's .NET initiative is explored in
97+
detail in this deep programmer's reference.</description>
98+
</book>
99+
<book id="bk111">
100+
<author>O'Brien, Tim</author>
101+
<title>MSXML3: A Comprehensive Guide</title>
102+
<genre>Computer</genre>
103+
<price>36.95</price>
104+
<publish_date>2000-12-01</publish_date>
105+
<description>The Microsoft MSXML3 parser is covered in
106+
detail, with attention to XML DOM interfaces, XSLT processing,
107+
SAX and more.</description>
108+
</book>
109+
<book id="bk112">
110+
<author>Galos, Mike</author>
111+
<title>Visual Studio 7: A Comprehensive Guide</title>
112+
<genre>Computer</genre>
113+
<price>49.95</price>
114+
<publish_date>2001-04-16</publish_date>
115+
<description>Microsoft Visual Studio 7 is explored in depth,
116+
looking at how Visual Basic, Visual C++, C#, and ASP+ are
117+
integrated into a comprehensive development
118+
environment.</description>
119+
</book>
120+
</catalog>
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
{
2+
"catalog": {
3+
"book": [
4+
{
5+
"@id": "bk101",
6+
"author": "Gambardella, Matthew",
7+
"title": "XML Developer's Guide",
8+
"genre": "Computer",
9+
"price": "44.95",
10+
"publish_date": "2000-10-01",
11+
"description": "An in-depth look at creating applications \n with XML."
12+
},
13+
{
14+
"@id": "bk102",
15+
"author": "Ralls, Kim",
16+
"title": "Midnight Rain",
17+
"genre": "Fantasy",
18+
"price": "5.95",
19+
"publish_date": "2000-12-16",
20+
"description": "A former architect battles corporate zombies, \n an evil sorceress, and her own childhood to become queen \n of the world."
21+
},
22+
{
23+
"@id": "bk103",
24+
"author": "Corets, Eva",
25+
"title": "Maeve Ascendant",
26+
"genre": "Fantasy",
27+
"price": "5.95",
28+
"publish_date": "2000-11-17",
29+
"description": "After the collapse of a nanotechnology \n society in England, the young survivors lay the \n foundation for a new society."
30+
},
31+
{
32+
"@id": "bk104",
33+
"author": "Corets, Eva",
34+
"title": "Oberon's Legacy",
35+
"genre": "Fantasy",
36+
"price": "5.95",
37+
"publish_date": "2001-03-10",
38+
"description": "In post-apocalypse England, the mysterious \n agent known only as Oberon helps to create a new life \n for the inhabitants of London. Sequel to Maeve \n Ascendant."
39+
},
40+
{
41+
"@id": "bk105",
42+
"author": "Corets, Eva",
43+
"title": "The Sundered Grail",
44+
"genre": "Fantasy",
45+
"price": "5.95",
46+
"publish_date": "2001-09-10",
47+
"description": "The two daughters of Maeve, half-sisters, \n battle one another for control of England. Sequel to \n Oberon's Legacy."
48+
},
49+
{
50+
"@id": "bk106",
51+
"author": "Randall, Cynthia",
52+
"title": "Lover Birds",
53+
"genre": "Romance",
54+
"price": "4.95",
55+
"publish_date": "2000-09-02",
56+
"description": "When Carla meets Paul at an ornithology \n conference, tempers fly as feathers get ruffled."
57+
},
58+
{
59+
"@id": "bk107",
60+
"author": "Thurman, Paula",
61+
"title": "Splish Splash",
62+
"genre": "Romance",
63+
"price": "4.95",
64+
"publish_date": "2000-11-02",
65+
"description": "A deep sea diver finds true love twenty \n thousand leagues beneath the sea."
66+
},
67+
{
68+
"@id": "bk108",
69+
"author": "Knorr, Stefan",
70+
"title": "Creepy Crawlies",
71+
"genre": "Horror",
72+
"price": "4.95",
73+
"publish_date": "2000-12-06",
74+
"description": "An anthology of horror stories about roaches,\n centipedes, scorpions and other insects."
75+
},
76+
{
77+
"@id": "bk109",
78+
"author": "Kress, Peter",
79+
"title": "Paradox Lost",
80+
"genre": "Science Fiction",
81+
"price": "6.95",
82+
"publish_date": "2000-11-02",
83+
"description": "After an inadvertant trip through a Heisenberg\n Uncertainty Device, James Salway discovers the problems \n of being quantum."
84+
},
85+
{
86+
"@id": "bk110",
87+
"author": "O'Brien, Tim",
88+
"title": "Microsoft .NET: The Programming Bible",
89+
"genre": "Computer",
90+
"price": "36.95",
91+
"publish_date": "2000-12-09",
92+
"description": "Microsoft's .NET initiative is explored in \n detail in this deep programmer's reference."
93+
},
94+
{
95+
"@id": "bk111",
96+
"author": "O'Brien, Tim",
97+
"title": "MSXML3: A Comprehensive Guide",
98+
"genre": "Computer",
99+
"price": "36.95",
100+
"publish_date": "2000-12-01",
101+
"description": "The Microsoft MSXML3 parser is covered in \n detail, with attention to XML DOM interfaces, XSLT processing, \n SAX and more."
102+
},
103+
{
104+
"@id": "bk112",
105+
"author": "Galos, Mike",
106+
"title": "Visual Studio 7: A Comprehensive Guide",
107+
"genre": "Computer",
108+
"price": "49.95",
109+
"publish_date": "2001-04-16",
110+
"description": "Microsoft Visual Studio 7 is explored in depth,\n looking at how Visual Basic, Visual C++, C#, and ASP+ are \n integrated into a comprehensive development \n environment."
111+
}
112+
]
113+
}
114+
}

0 commit comments

Comments
 (0)