{"id":15713750,"url":"https://github.com/naqvis/json-xpath","last_synced_at":"2026-04-27T23:33:25.381Z","repository":{"id":88081911,"uuid":"260519943","full_name":"naqvis/json-xpath","owner":"naqvis","description":"Provide XPath support on JSON document","archived":false,"fork":false,"pushed_at":"2021-04-04T16:44:19.000Z","size":14,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-30T18:47:23.299Z","etag":null,"topics":["crystal","crystal-lang","crystal-language","json","json-xpath","xpath2"],"latest_commit_sha":null,"homepage":"","language":"Crystal","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/naqvis.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-05-01T17:37:16.000Z","updated_at":"2022-10-12T23:36:04.000Z","dependencies_parsed_at":"2023-05-18T05:00:14.119Z","dependency_job_id":null,"html_url":"https://github.com/naqvis/json-xpath","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/naqvis/json-xpath","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/naqvis%2Fjson-xpath","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/naqvis%2Fjson-xpath/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/naqvis%2Fjson-xpath/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/naqvis%2Fjson-xpath/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/naqvis","download_url":"https://codeload.github.com/naqvis/json-xpath/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/naqvis%2Fjson-xpath/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32360110,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-27T20:07:02.737Z","status":"ssl_error","status_checked_at":"2026-04-27T20:07:00.910Z","response_time":128,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["crystal","crystal-lang","crystal-language","json","json-xpath","xpath2"],"created_at":"2024-10-03T21:33:11.065Z","updated_at":"2026-04-27T23:33:25.367Z","avatar_url":"https://github.com/naqvis.png","language":"Crystal","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JSON XPath\n[![Build Status](https://travis-ci.org/naqvis/json-xpath.svg?branch=master)](https://travis-ci.org/naqvis/json-xpath)\n[![GitHub release](https://img.shields.io/github/release/naqvis/json-xpath.svg)](https://github.com/naqvis/json-xpath/releases)\n[![Docs](https://img.shields.io/badge/docs-available-brightgreen.svg)](https://naqvis.github.io/json-xpath/)\n\nJSON XPath shard provides XPath query functionality for JSON document, it lets you extract data from JSON documents through an XPath expression.\n\n## Installation\n\n1. Add the dependency to your `shard.yml`:\n\n   ```yaml\n   dependencies:\n     json-xpath:\n       github: naqvis/json-xpath\n   ```\n\n2. Run `shards install`\n\n## Usage\n\n```crystal\nrequire \"json-xpath\"\n\njson = \u003c\u003c-JSON\n{\n \"store\": {\n     \"book\": [\n         {\n             \"category\": \"reference\",\n             \"author\": \"Nigel Rees\",\n             \"title\": \"Sayings of the Century\",\n             \"price\": 8.95\n         },\n         {\n             \"category\": \"fiction\",\n             \"author\": \"Evelyn Waugh\",\n             \"title\": \"Sword of Honour\",\n             \"price\": 12.99\n         },\n         {\n             \"category\": \"fiction\",\n             \"author\": \"Herman Melville\",\n             \"title\": \"Moby Dick\",\n             \"isbn\": \"0-553-21311-3\",\n             \"price\": 8.99\n         },\n         {\n             \"category\": \"fiction\",\n             \"author\": \"J. R. R. Tolkien\",\n             \"title\": \"The Lord of the Rings\",\n             \"isbn\": \"0-395-19395-8\",\n             \"price\": 22.99\n         }\n     ],\n     \"bicycle\": {\n         \"color\": \"red\",\n         \"price\": 19.95\n     }\n }\n}\nJSON\n\nbooks = JSONXPath.parse(json)\n\n# Find authors of all books in the store\nlist = books.xpath_nodes(\"store/book/*/author\")\n# OR\n# list = books.xpath_nodes(\"//author\")\n\nlist.each { |a| puts a.content }\n# =\u003e Nigel Rees\n# =\u003e Evelyn Waugh\n# =\u003e Herman Melville\n# =\u003e J. R. R. Tolkien\n\n# Find the Third book\nbook = books.xpath(\"//book/*[3]\")\nbook.try \u0026.children.each { |a| puts \"#{a.data} : #{a.content}\" }\n\n# =\u003e author : Herman Melville\n# =\u003e category : fiction\n# =\u003e isbn : 0-553-21311-3\n# =\u003e price : 8.99\n# =\u003e title : Moby Dick\n\n# Find the last book\nbook = books.xpath(\"//book/*[last()]\")\nbook.try \u0026.children.each { |a| puts \"#{a.data} : #{a.content}\" }\n\n# =\u003e  author : J. R. R. Tolkien\n# =\u003e  category : fiction\n# =\u003e  isbn : 0-395-19395-8\n# =\u003e  price : 22.99\n# =\u003e  title : The Lord of the Rings\n\n# OR call `raw` property to retrive raw JSON\npp book.try \u0026.raw\n\n# =\u003e {\"category\" =\u003e \"fiction\",\n# \"author\" =\u003e \"J. R. R. Tolkien\",\n# \"title\" =\u003e \"The Lord of the Rings\",\n# \"isbn\" =\u003e \"0-395-19395-8\",\n#\"price\" =\u003e 22.99}\n\n# Find all books with isbn number\nlist = books.xpath_nodes(\"//book/*[isbn]\")\nputs list.size # =\u003e 2\n\n# Find all books cheaper than 10\nlist = books.xpath_nodes(\"//book/*[price\u003c10]\")\nputs list.size # =\u003e 2\n\n# Sum the price of all books\nprice = books.xpath_float(\"sum(//book/*/price)\")\nputs price # =\u003e 53.92\n```\n\nrefer to `spec` for usage examples. And refer to [Crystal XPath2 Shard](https://github.com/naqvis/crystal-xpath2) for details of what functions and functionality is supported by XPath implementation.\n\n## Development\n\nTo run all tests:\n\n```\ncrystal spec\n```\n\n## Contributing\n\n1. Fork it (\u003chttps://github.com/naqvis/json-xpath/fork\u003e)\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n\n## Contributors\n\n- [Ali Naqvi](https://github.com/naqvis) - creator and maintainer\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnaqvis%2Fjson-xpath","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnaqvis%2Fjson-xpath","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnaqvis%2Fjson-xpath/lists"}