uh hello guys welcome to this video so
in this video I will show you how to
convert your XML file into JSON inside
NodeJS in the terminal and for this
we'll be using a third party package
called as fast XML parser it will parse
the content inside your extensible
markup language so we have this file
here which actually contain these
records and I will try to convert this
into a JSON file so as I run the script
here you will see on the left hand side
it will convert this XML into JSON and
we get this message XML to JSON
conversion complete and the get this
output
file output dojson you will see it
creates an array of objects and all your
XML data has been exported to
JSON and for this you need to install
this third party package which is fast
XML parser
so the command is very simple you
install this package by executing this
command i've already done that so first
of all I will show you how to do this
line by line so we need to require the
file system module which is a built-in
module of
NodeJS and then we also need to
import this uh
XML third party
package fast XML
parser from this we are using this uh
method XML parser so after that we
actually take the input file input XML
file so we use the file system module
which contains this function read file
synchronously we provide the file name
which will be
output.xml and we use the UTF8 encoding
type so after we read the XML file we
basically create a parser instance
so we create new XML parser new instance
of it and then we convert this XML into
JSON
object by using this function parser dot
parse and here we pass the XML data so
it will create a JSON object for us and
now we need to save this JSON file for
saving this JSON file we again use the
file system module which contains this
function write file synchronously and
here we specify the output file
name JSON object second will be the
output file name which will
be sorry the first argument will be
your output file name so output JSON and
then we need to convert this into JSON
so JSON stringify
file JSON object null to that's all so
then we can show a notification to the
user that your XML data has been
converted to JSON and saved to this file
so let me delete this uh output JSON
before executing the script so once
again if you run the
script you will see this message
appearing and your data output.json has
been created so in this easy way guys
you can carry out the conversion using
this third party module in NodeJS fast
XML parser so thank you very much for
watching this video and also check out
my website
freemediattools.com which contains
thousands of tools