{"id":25067350,"url":"https://github.com/digitalheir/ruby-xml-to-json","last_synced_at":"2025-04-14T20:12:04.964Z","repository":{"id":33767454,"uuid":"37423361","full_name":"digitalheir/ruby-xml-to-json","owner":"digitalheir","description":"Ruby gem to serialize Nokogiri XML documents into JSON","archived":false,"fork":false,"pushed_at":"2015-06-15T10:21:33.000Z","size":148,"stargazers_count":18,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-14T20:12:04.756Z","etag":null,"topics":["json","nokogiri","ruby","xml","xml-to-json"],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/digitalheir.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-06-14T18:03:21.000Z","updated_at":"2025-01-16T12:05:38.000Z","dependencies_parsed_at":"2022-09-01T12:02:25.288Z","dependency_job_id":null,"html_url":"https://github.com/digitalheir/ruby-xml-to-json","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/digitalheir%2Fruby-xml-to-json","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/digitalheir%2Fruby-xml-to-json/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/digitalheir%2Fruby-xml-to-json/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/digitalheir%2Fruby-xml-to-json/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/digitalheir","download_url":"https://codeload.github.com/digitalheir/ruby-xml-to-json/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248952350,"owners_count":21188426,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["json","nokogiri","ruby","xml","xml-to-json"],"created_at":"2025-02-06T20:55:33.450Z","updated_at":"2025-04-14T20:12:04.942Z","avatar_url":"https://github.com/digitalheir.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# XML to JSON\n[![Build Status](https://travis-ci.org/digitalheir/ruby-xml-to-json.svg?branch=master)](https://travis-ci.org/digitalheir/ruby-xml-to-json)\n[![Code Climate](https://codeclimate.com/github/digitalheir/ruby-xml-to-json/badges/gpa.svg)](https://codeclimate.com/github/digitalheir/ruby-xml-to-json)\n[![Test Coverage](https://codeclimate.com/github/digitalheir/ruby-xml-to-json/badges/coverage.svg)](https://codeclimate.com/github/digitalheir/ruby-xml-to-json/coverage)\n\nThis Ruby gem adds a `to_hash` and `to_json` method to Nokogiri XML nodes, allowing us to serialize arbitrary XML nodes to JSON.\n\nThis gem also picks up attributes, comments, processing instructions and doctype declarations. The result is wordy, but complete.\n\nAs an added bonus, line numbers are included where possible.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'xml-to-json'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install xml-to-json\n\n## Usage\n\n```ruby\nrequire 'xml/to/json'\n\nxml_string = STR_XML = \u003c\u003c-EOS\n                       \u003c!DOCTYPE dtd-name [\n                          \u003c!ENTITY entity_1 \"Has been ëxpÄnded\"\u003e\n                          \u003c!ENTITY entity_system SYSTEM \"mt_cook1.jpg\"\u003e\n                          \u003c!ENTITY name_public PUBLIC \"entity_public_id\" \"URI\"\u003e\n                          \u003c!NOTATION notation-system SYSTEM \"notation-id-system\"\u003e\n                          \u003c!NOTATION NoTaTiOn-PuBLiC PUBLIC \"notation-id-public\"\u003e\n                          \u003c!ELEMENT div1 (head,\n                       (p | list | note)*,\n                       div2*)\u003e\n                          \u003c!ELEMENT photo (hello)\u003e\n                          \u003c!ATTLIST photo some-attribute CDATA #REQUIRED\u003e\n                          \u003c!ATTLIST\n                            photo photo_att ENTITY #IMPLIED\n                            photo NOTATION (notation-system | NoTaTiOn-PuBLiC | notation-system) #IMPLIED\u003e\n                       ]\u003e\n\n                       \u003cmyRoot xml:id=\"root\" xml:lang=\"en\"\u003e\n                             some text\n                             \u003c!--\n                             In comments we can use ]]\u003e\n                             \u003c\n                             \u0026,\n                       ',\n                       and \",\n                       but %MyParamEntity; will not be expanded--\u003e\n                             \u003c![CDATA[\n                             Character Data block \u003c!-- \u003c,\n                       \u0026 ' \" --\u003e  *and* %MyParamEntity;\n                             ]]\u003e\n                             \u003c?linebreak?\u003e\n                             \u003cdeeper xmlns=\"lol://some-namespace\" how-deep=\"very-deep\"\u003e☠☠☠randomtext☠☠☠\n                             \u003ceven\n                               lol:my-attr=\"just an attribute\"\n                               xmlns:lol=\\'lol://my.name.space/\\' deeper=\"true\"\u003e\u0026amp;\u003c/even\u003e\u003c/deeper\u003e\n                       \u003c/myRoot\u003e\nEOS\n\nxml = Nokogiri::XML STR_XML\nputs JSON.pretty_generate(xml.root) # Use xml for information about the document, like DTD and stuff\n```\n\nproduces\n\n```json\n{\n  \"type\": \"element\",\n  \"name\": \"myRoot\",\n  \"attributes\": [\n    {\n      \"type\": \"attribute\",\n      \"name\": \"id\",\n      \"content\": \"root\",\n      \"line\": 17,\n      \"namespace\": {\n        \"href\": \"http://www.w3.org/XML/1998/namespace\",\n        \"prefix\": \"xml\"\n      }\n    },\n    {\n      \"type\": \"attribute\",\n      \"name\": \"lang\",\n      \"content\": \"en\",\n      \"line\": 17,\n      \"namespace\": {\n        \"href\": \"http://www.w3.org/XML/1998/namespace\",\n        \"prefix\": \"xml\"\n      }\n    }\n  ],\n  \"line\": 17,\n  \"children\": [\n    {\n      \"type\": \"text\",\n      \"content\": \"\\n                             some text\\n                             \",\n      \"line\": 19\n    },\n    {\n      \"type\": \"comment\",\n      \"content\": \"\\n                             In comments we can use ]]\u003e\\n                             \u003c\\n                             \u0026,\\n                       ',\\n                       and \\\",\\n                       but %MyParamEntity; will not be expanded\",\n      \"line\": 25\n    },\n    {\n      \"type\": \"text\",\n      \"content\": \"\\n                             \",\n      \"line\": 26\n    },\n    {\n      \"type\": \"cdata\",\n      \"name\": \"#cdata-section\",\n      \"content\": \"\\n                             Character Data block \u003c!-- \u003c,\\n                       \u0026 ' \\\" --\u003e  *and* %MyParamEntity;\\n                             \",\n      \"line\": 26\n    },\n    {\n      \"type\": \"text\",\n      \"content\": \"\\n                             \",\n      \"line\": 30\n    },\n    {\n      \"type\": \"pi\",\n      \"name\": \"linebreak\",\n      \"line\": 30\n    },\n    {\n      \"type\": \"text\",\n      \"content\": \"\\n                             \",\n      \"line\": 31\n    },\n    {\n      \"type\": \"element\",\n      \"name\": \"deeper\",\n      \"attributes\": [\n        {\n          \"type\": \"attribute\",\n          \"name\": \"how-deep\",\n          \"content\": \"very-deep\",\n          \"line\": 31\n        }\n      ],\n      \"line\": 31,\n      \"namespace\": {\n        \"href\": \"lol://some-namespace\"\n      },\n      \"children\": [\n        {\n          \"type\": \"text\",\n          \"content\": \"☠☠☠randomtext☠☠☠\\n                             \",\n          \"line\": 32\n        },\n        {\n          \"type\": \"element\",\n          \"name\": \"even\",\n          \"attributes\": [\n            {\n              \"type\": \"attribute\",\n              \"name\": \"my-attr\",\n              \"content\": \"just an attribute\",\n              \"line\": 34,\n              \"namespace\": {\n                \"href\": \"lol://my.name.space/\",\n                \"prefix\": \"lol\"\n              }\n            },\n            {\n              \"type\": \"attribute\",\n              \"name\": \"deeper\",\n              \"content\": \"true\",\n              \"line\": 34\n            }\n          ],\n          \"line\": 34,\n          \"namespace\": {\n            \"href\": \"lol://some-namespace\"\n          },\n          \"children\": [\n            {\n              \"type\": \"text\",\n              \"content\": \"\u0026\",\n              \"line\": 34\n            }\n          ]\n        }\n      ]\n    },\n    {\n      \"type\": \"text\",\n      \"content\": \"\\n                       \",\n      \"line\": 35\n    }\n  ]\n}\n```\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/digitalheir/ruby-xml-to-json. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](CODE_OF_CONDUCT).\n\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdigitalheir%2Fruby-xml-to-json","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdigitalheir%2Fruby-xml-to-json","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdigitalheir%2Fruby-xml-to-json/lists"}