{"id":20409149,"url":"https://github.com/tcorral/jsfromxml","last_synced_at":"2026-04-19T02:33:16.516Z","repository":{"id":27030150,"uuid":"30494999","full_name":"tcorral/jsfromxml","owner":"tcorral","description":"XML to Javascript object converter","archived":false,"fork":false,"pushed_at":"2015-02-10T12:24:44.000Z","size":196,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-22T18:02:52.572Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tcorral.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-02-08T15:19:13.000Z","updated_at":"2015-02-10T12:24:44.000Z","dependencies_parsed_at":"2022-08-03T06:30:39.550Z","dependency_job_id":null,"html_url":"https://github.com/tcorral/jsfromxml","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/tcorral/jsfromxml","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tcorral%2Fjsfromxml","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tcorral%2Fjsfromxml/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tcorral%2Fjsfromxml/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tcorral%2Fjsfromxml/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tcorral","download_url":"https://codeload.github.com/tcorral/jsfromxml/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tcorral%2Fjsfromxml/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31991999,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-18T20:23:30.271Z","status":"online","status_checked_at":"2026-04-19T02:00:07.110Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-15T05:39:50.386Z","updated_at":"2026-04-19T02:33:16.492Z","avatar_url":"https://github.com/tcorral.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JSfromXML is a XML \u003e\u003c Javascript Object/JSON converter\n\n[![Build Status](https://travis-ci.org/tcorral/jsfromxml.png)](https://travis-ci.org/tcorral/jsfromxml)\n[![Code Climate](https://codeclimate.com/github/tcorral/jsfromxml/badges/gpa.svg)](https://codeclimate.com/github/tcorral/jsfromxml)\n\nThis module reads your XML files and converts them to a Javascript object. Yes, I know that there are a lot XML to JSON converters\nand parsers but they did not work for me, because their leak of usability. The idea of this new converter is to\nremain as easy and usable as possible. I´m open to include those improvements you think that could make it better.\n\n## Installation\n```\n$ npm install jsfromxml\n```\n\n## How it works\nI was very disappointed with the usage of other nodes so I decided to improve the api to access the elements, their\nvalues and their attributes.\n\nThe root node will be a single member of the Javascript object.\n\nThe children nodes will be contained in an object with the key *\"\u003e\"*.\n\n* If the key of one node exist just one time it will be an object with the key of the children name.\n* If the key of one node exist more than one time it will be an array with all the objects inside.\n\nThe attributes will be contained in an object with the key *\"@\"*.\n\nThe value of the node will be contained as a string in a member with the key *\"$\"*.\n\nExample XML code:\n\n```xml\n\n    \u003c?xml version=\"1.0\"?\u003e\n    \u003cPurchaseOrder PurchaseOrderNumber=\"99503\" OrderDate=\"1999-10-20\"\u003e\n        \u003cAddress Type=\"Shipping\"\u003e\n            \u003cName\u003eEllen Adams\u003c/Name\u003e\n            \u003cStreet\u003e123 Maple Street\u003c/Street\u003e\n            \u003cCity\u003eMill Valley\u003c/City\u003e\n            \u003cState\u003eCA\u003c/State\u003e\n            \u003cZip\u003e10999\u003c/Zip\u003e\n            \u003cCountry\u003eUSA\u003c/Country\u003e\n        \u003c/Address\u003e\n        \u003cAddress Type=\"Billing\"\u003e\n            \u003cName\u003eTai Yee\u003c/Name\u003e\n            \u003cStreet\u003e8 Oak Avenue\u003c/Street\u003e\n            \u003cCity\u003eOld Town\u003c/City\u003e\n            \u003cState\u003ePA\u003c/State\u003e\n            \u003cZip\u003e95819\u003c/Zip\u003e\n            \u003cCountry\u003eUSA\u003c/Country\u003e\n        \u003c/Address\u003e\n        \u003cDeliveryNotes\u003ePlease leave packages in shed by driveway.\u003c/DeliveryNotes\u003e\n        \u003cItems\u003e\n            \u003cItem PartNumber=\"872-AA\"\u003e\n                \u003cProductName\u003eLawnmower\u003c/ProductName\u003e\n                \u003cQuantity\u003e1\u003c/Quantity\u003e\n                \u003cUSPrice\u003e148.95\u003c/USPrice\u003e\n                \u003cComment\u003eConfirm this is electric\u003c/Comment\u003e\n            \u003c/Item\u003e\n            \u003cItem PartNumber=\"926-AA\"\u003e\n                \u003cProductName\u003eBaby Monitor\u003c/ProductName\u003e\n                \u003cQuantity\u003e2\u003c/Quantity\u003e\n                \u003cUSPrice\u003e39.98\u003c/USPrice\u003e\n                \u003cShipDate\u003e1999-05-21\u003c/ShipDate\u003e\n            \u003c/Item\u003e\n        \u003c/Items\u003e\n    \u003c/PurchaseOrder\u003e\n```\nExample of the result:\n\n```javascript\n    {\n       \"PurchaseOrder\":{\n          \"@\":{\n             \"PurchaseOrderNumber\":\"99503\",\n             \"OrderDate\":\"1999-10-20\"\n          },\n          \"\u003e\":{\n             \"Address\":[\n                {\n                   \"@\":{\n                      \"Type\":\"Shipping\"\n                   },\n                   \"\u003e\":{\n                      \"Name\":\"Ellen Adams\",\n                      \"Street\":\"123 Maple Street\",\n                      \"City\":\"Mill Valley\",\n                      \"State\":\"CA\",\n                      \"Zip\":\"10999\",\n                      \"Country\":\"USA\"\n                   }\n                },\n                {\n                   \"@\":{\n                      \"Type\":\"Billing\"\n                   },\n                   \"\u003e\":{\n                      \"Name\":\"Tai Yee\",\n                      \"Street\":\"8 Oak Avenue\",\n                      \"City\":\"Old Town\",\n                      \"State\":\"PA\",\n                      \"Zip\":\"95819\",\n                      \"Country\":\"USA\"\n                   }\n                }\n             ],\n             \"DeliveryNotes\":\"Please leave packages in shed by driveway.\",\n             \"Items\":{\n                \"\u003e\":{\n                   \"Item\":[\n                      {\n                         \"@\":{\n                            \"PartNumber\":\"872-AA\"\n                         },\n                         \"\u003e\":{\n                            \"ProductName\":\"Lawnmower\",\n                            \"Quantity\":\"1\",\n                            \"USPrice\":\"148.95\",\n                            \"Comment\":\"Confirm this is electric\"\n                         }\n                      },\n                      {\n                         \"@\":{\n                            \"PartNumber\":\"926-AA\"\n                         },\n                         \"\u003e\":{\n                            \"ProductName\":\"Baby Monitor\",\n                            \"Quantity\":\"2\",\n                            \"USPrice\":\"39.98\",\n                            \"ShipDate\":\"1999-05-21\"\n                         }\n                      }\n                   ]\n                }\n             }\n          }\n       }\n    }\n```\n\nIf you want to access the addresses for this purchase order you just need to do:\n\n```javascript\nvar adresses = json.PurchaseOrder[\"\u003e\"].Address;\n```\n\nIf you want to access the \"PartNumber\" attribute of the first item you just need to:\n\n```javascript\nvar partNumber = json.PurchaseOrder[\"\u003e\"].Items[\"\u003e\"].Item[0][\"@\"].PartNumber;\n```\n\nIf you want to access the \"Delivery Notes\" value you just need to:\n\n```javascript\nvar partNumber = json.PurchaseOrder[\"\u003e\"].DeliveryNotes;\n```\n\n## Basic Usage - XML to JSON\n\n```javascript\nvar parser = require('jsonfromxml');\n\nparser.toJSONFromFile(\"path/to/a/xml/file.xml\", function (err, json){\n    // json contains a Javascript object with the content of the xml.\n    console.log(json);\n});\n```\n\n## Basic Usage - JSON to XML\n\n```javascript\nvar parser = require('jsonfromxml');\n\nparser.toXMLFromFile(\"path/to/a/xml/file.json\", function (err, xml){\n    // xml contains the xml in string format.\n    console.log(xml);\n});\n```\n\n## API\n\n### toJsObject(xml, callback)\n\nParameters:\n- xml - ```String```\n- callback - ```Function```\n\nReturns:\n- Javascript Object - ```Object```\n\n#### Usage\n\n```javascript\nparser.toJsObject(xml, callback);\n```\n\n### toJSON(xml, callback)\n\nParameters:\n- xml - ```String```\n- callback - ```Function```\n\nReturns:\n- JSON - ```String```\n\n#### Usage\n\n```javascript\nparser.toJson(xml, callback);\n```\n\n### toJsObjectFromFile(filepath, callback)\n\nParameters:\n- filepath - ```String```\n- callback - ```Function```\n\nReturns:\n- Javascript Object - ```Object```\n\n#### Usage\n\n```javascript\nparser.toJsObjectFromFile(filepath, callback);\n```\n\n### toJSONFromFile(filepath, callback)\n\nParameters:\n- filepath - ```String```\n- callback - ```Function```\n\nReturns:\n- Javascript Object - ```Object```\n\n#### Usage\n\n```javascript\nparser.toJSONFromFile(filepath, callback);\n```\n\n### toXML(js, callback)\n\nParameters:\n- js - ```Object```\n- callback - ```Function```\n\nReturns:\n- XML - ```String```\n\n#### Usage\n\n```javascript\nparser.toXML(js, callback);\n```\n\n### toXMLFromJSON(json, callback)\n\nParameters:\n- json - ```String```\n- callback - ```Function```\n\nReturns:\n- XML - ```String```\n\n#### Usage\n\n```javascript\nparser.toXMLFromJSON(json, callback);\n```\n\n### toXMLFromFile(filepath, callback)\n\nParameters:\n- filepath - ```String```\n- callback - ```Function```\n\nReturns:\n- XML - ```String```\n\n#### Usage\n\n```javascript\nparser.toXMLFromFile(filepath, callback);\n```\n\n## License\n(The MIT License)\n\nCopyright 2014 Tomas Corral. All rights reserved.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to\ndeal in the Software without restriction, including without limitation the\nrights to use, copy, modify, merge, publish, distribute, sublicense, and/or\nsell copies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\nFROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\nIN THE SOFTWARE.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftcorral%2Fjsfromxml","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftcorral%2Fjsfromxml","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftcorral%2Fjsfromxml/lists"}