# Graphml2json This utility takes graphml and converts it to json suitable for use in D3 ## Installation Add this line to your application's Gemfile: gem 'graphml2json' And then execute: $ bundle Or install it yourself as: $ gem install graphml2json ## Usage ### From ruby ``` >> require 'open-uri' >> require 'graphml2json' >> data = open('http://graphml.graphdrawing.org/primer/attributes.graphml').read => "\n\n\n \n yellow\n \n \n \n \n green\n \n \n \n blue\n \n \n red\n \n \n \n turquoise\n \n \n 1.0\n \n \n 1.0\n \n \n 2.0\n \n \n \n \n \n 1.1\n \n \n\n" >> Graphml2Json.generate(data) => "{\"nodes\":[{\"name\":0,\"d0\":\"green\"},{\"name\":1},{\"name\":2,\"d0\":\"blue\"},{\"name\":3,\"d0\":\"red\"},{\"name\":4},{\"name\":5,\"d0\":\"turquoise\"}],\"edges\":[{\"source\":0,\"target\":2,\"d1\":\"1.0\"},{\"source\":0,\"target\":1,\"d1\":\"1.0\"},{\"source\":1,\"target\":3,\"d1\":\"2.0\"},{\"source\":3,\"target\":2},{\"source\":2,\"target\":4},{\"source\":3,\"target\":5},{\"source\":5,\"target\":4,\"d1\":\"1.1\"}]}" ``` ### From a terminal You can also invoke the `graphml2json` utility from the command line. It takes stdin as input. ``` $ curl http://graphml.graphdrawing.org/primer/attributes.graphml | graphml2json | json_pp { "nodes" : [ { "d0" : "green", "name" : 0 }, { "name" : 1 }, { "name" : 2, "d0" : "blue" }, { "name" : 3, "d0" : "red" }, { "name" : 4 }, { "d0" : "turquoise", "name" : 5 } ], "edges" : [ { "d1" : "1.0", "source" : 0, "target" : 2 }, { "target" : 1, "d1" : "1.0", "source" : 0 }, { "source" : 1, "d1" : "2.0", "target" : 3 }, { "target" : 2, "source" : 3 }, { "source" : 2, "target" : 4 }, { "source" : 3, "target" : 5 }, { "d1" : "1.1", "source" : 5, "target" : 4 } ] } ``` ### Usage From Docker cd docker_runner docker build -t graphml2json . # notice no `t` in docker run command curl http://graphml.graphdrawing.org/primer/attributes.graphml | docker run -i --rm graphml2json ### For Docker Dev docker build -t graphml_dev . # run tests docker run -it --rm graphml_dev ## Changelog * [changelog](https://github.com/gregors/graphml2json/blob/master/CHANGELOG.md) ## Contributing 1. Fork it 2. Create your feature branch (`git checkout -b my-new-feature`) 3. Commit your changes (`git commit -am 'Add some feature'`) 4. Push to the branch (`git push origin my-new-feature`) 5. Create new Pull Request