0:00
uh hello guys welcome to this video so
0:02
in this video I will show you how to
0:04
convert your XML file into JSON inside
0:07
NodeJS in the terminal and for this
0:10
we'll be using a third party package
0:12
called as fast XML parser it will parse
0:15
the content inside your extensible
0:17
markup language so we have this file
0:19
here which actually contain these
0:22
records and I will try to convert this
0:25
into a JSON file so as I run the script
0:29
here you will see on the left hand side
0:31
it will convert this XML into JSON and
0:34
we get this message XML to JSON
0:36
conversion complete and the get this
0:40
file output dojson you will see it
0:42
creates an array of objects and all your
0:46
XML data has been exported to
0:49
JSON and for this you need to install
0:52
this third party package which is fast
0:58
so the command is very simple you
1:02
install this package by executing this
1:04
command i've already done that so first
1:06
of all I will show you how to do this
1:08
line by line so we need to require the
1:10
file system module which is a built-in
1:14
NodeJS and then we also need to
1:27
parser from this we are using this uh
1:30
method XML parser so after that we
1:34
actually take the input file input XML
1:38
file so we use the file system module
1:40
which contains this function read file
1:44
synchronously we provide the file name
1:50
output.xml and we use the UTF8 encoding
1:59
type so after we read the XML file we
2:03
basically create a parser instance
2:06
so we create new XML parser new instance
2:11
of it and then we convert this XML into
2:16
object by using this function parser dot
2:20
parse and here we pass the XML data so
2:24
it will create a JSON object for us and
2:26
now we need to save this JSON file for
2:29
saving this JSON file we again use the
2:31
file system module which contains this
2:33
function write file synchronously and
2:37
here we specify the output file
2:40
name JSON object second will be the
2:43
output file name which will
2:47
be sorry the first argument will be
2:50
your output file name so output JSON and
2:54
then we need to convert this into JSON
3:00
file JSON object null to that's all so
3:04
then we can show a notification to the
3:06
user that your XML data has been
3:09
converted to JSON and saved to this file
3:12
so let me delete this uh output JSON
3:16
before executing the script so once
3:21
script you will see this message
3:23
appearing and your data output.json has
3:26
been created so in this easy way guys
3:28
you can carry out the conversion using
3:30
this third party module in NodeJS fast
3:33
XML parser so thank you very much for
3:36
watching this video and also check out
3:39
freemediattools.com which contains