0:00
uh hello guys welcome to this video so
0:02
in this video i will show you how to
0:04
convert the json file into xml file
0:07
inside nodejs inside the
0:09
terminal so we have this uh input json
0:13
file if you see in the same directory if
0:15
i open this you will see it contains
0:17
array of records array of json objects
0:20
each object having these
0:23
properties and i have basically written
0:27
script and as i run the script here you
0:30
will see on the left hand side it will
0:31
convert this json file into
0:34
xml here we just need to replace the
0:37
input file name which is input.json so
0:44
say and as soon as you run this you will
0:47
see json to xml conversion complete and
0:50
we actually create this output.xml file
0:54
and if i open this now you will see it
0:57
successfully converted your json file
0:59
into xml each record has been converted
1:03
so this is the format of xml extensible
1:08
uh each record if you see has been
1:10
successfully converted and there is a
1:13
specific package guys inside
1:15
nodejs which you can directly install by
1:20
js2 xml parser so this is the command
1:24
here to install this third party package
1:26
which automatically done this conversion
1:28
from uh json to xml so just install this
1:32
i've already installed it and now i will
1:35
show you step by step so first of all we
1:38
need the file system module for this and
1:41
then we also need this module jso
1:46
toxml parser and we just need to require
1:49
this package which is
1:53
js so we just required this package and
1:56
after that we read the input json file
2:00
and by using this json.parse function
2:03
and inside this we actually use the file
2:06
system module and we read the file by
2:08
using this function read file
2:11
synchronize and here we
2:13
specify the file name which will be
2:18
json so it's present in the same
2:20
directory so we are just passing the
2:23
name after that we create an variable
2:27
xml and here we carry out the conversion
2:30
by using this package js to xml
2:34
parser so we parse the json by using
2:37
this package and it actually
2:40
contains a function which will be
2:44
parse and here we specify the root here
2:48
root element i will say root and then
2:50
the json data that needs to be converted
2:54
so now we just need to create the output
2:56
file which will be write file
3:00
synchronize to create the
3:02
output xml file so output
3:07
doxml and then the actual xml and then
3:11
we can show a simple notification that
3:14
xml file created successfully so you can
3:17
that if i now delete this xml file here
3:25
script so just run the script here node
3:29
index.js you will see on the left hand
3:31
side your xml file is created
3:34
successfully if i open this you will see
3:37
all your data has been successfully
3:39
converted from json to xml using this
3:42
package in nodejs so thank you very much
3:44
for watching this video and also check
3:48
freetools.com which contains thousands