XML2JSON(1p)
π NAME π
okay bestie, gather round β this is xml2json, and what it does is convert an XML message with a schema into JSON. that's it, that's the whole vibe. π
β¨ SYNOPSIS β¨
two ways to run it, pick ur fighter:
xml2json xml-file schema-file(s) >json-file
xml2json -x xml-file -s schema-files -o json-file
π¦ DESCRIPTION π¦
so basically it takes an XML message and flips it into JSON with the exact same structure π«Ά. but here's the thing β you must hand it a schema, because the schema is what enforces the correct syntax, and it especially matters for optionally repeated elements (iykyk, those are the ones that get messy). no schema, no slay. π
πΈ Options πΈ
you've got two paths, bestie: either you pass an XML message filename plus one or more schema filenames as plain arguments, or you use the options. either way works, pick whichever feels right for ur soul.
--xml,-xfilename β this is the file holding the xml message. and if you put a single dash, that means "stdin" (yes queen, piping is valid). β¨--schema,-sfilename(s) β the schema file(s). you can repeat this option, or separate the filenames with comma's, if you've got more than one schema file to parse. β οΈ important: all imported and included schema components have to be provided explicitly β it won't go hunt them down for you. nope. you provide them. all of them. π--bigints,-b(boolean) β so by default the translation is a little sloppy: Integer types are defined to support at least 18 digits in XML. but honestly?? that's usually unnecessarily large and unreadible in JSON. so flip this and it stops being like that. π--no-keep-root(boolean) β do not include the top node in the output. bye to the root, it's giving minimalism. π--mixedHOW β[1.32]how to treat mixed elements. the default isTEXTUAL. other values are"ATTRIBUTES","XML_STRING", and"STRUCTURAL". if u want more details aboutmixed_elements, go check outXML::Compile::Translate::Readerβ that's where the lore lives. π--type,-tTYPE β the type of the root element. it's required if the XML is not namespaceo qualified, although the schema is. if you don't specify it, the root element is automatically inspected for you (she's self-sufficient like that). π§
the TYPE notation is "{namespace}localname". β οΈ and be warned β use quoting on the UNIX command-line, because curly braces have a special meaning for the shell. don't get got by ur own shell bestie, quote it. π
--output,-ofilename β where the JSON lands. by default (or when the filename is a dash), the output is printed to stdout. β¨
π₯ SEE ALSO π₯
this module is part of Perl's XML-Compile distribution. website: http://perl.overmeer.net/xml-compile/ β go peek, it's cute. πΈ
π LICENSE π
Copyrights 2017 by Slaven Rezic and Mark Overmeer. For other contributors see ChangeLog.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See http://www.perl.com/perl/misc/Artistic.html β
and that's the whole page, bestie!! π«Άπ this one's running on perl v5.40.0, dated 2024-10-27, and it's the XML2JSON(1p) manual β go forth and convert ur XML, u absolute icon πβ¨
π¦ where this page comes from
- debian trixie: libxml-compile-perl 1.64-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libxml-compile-perl 1.64-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libxml-compile-perl 1.64-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms