{"id":13344995,"url":"https://github.com/tomnomnom/gron","last_synced_at":"2025-05-08T22:28:04.637Z","repository":{"id":4582305,"uuid":"5724223","full_name":"tomnomnom/gron","owner":"tomnomnom","description":"Make JSON greppable!","archived":false,"fork":false,"pushed_at":"2024-11-29T23:37:22.000Z","size":1469,"stargazers_count":14073,"open_issues_count":65,"forks_count":330,"subscribers_count":90,"default_branch":"master","last_synced_at":"2025-05-08T17:08:23.380Z","etag":null,"topics":["cli","json"],"latest_commit_sha":null,"homepage":"","language":"Go","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/tomnomnom.png","metadata":{"files":{"readme":"README.mkd","changelog":"CHANGELOG.mkd","contributing":"CONTRIBUTING.mkd","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,"zenodo":null}},"created_at":"2012-09-08T00:46:07.000Z","updated_at":"2025-05-08T14:21:29.000Z","dependencies_parsed_at":"2024-01-03T04:14:26.610Z","dependency_job_id":"80ebe2e6-c031-46d1-a697-ec946e994756","html_url":"https://github.com/tomnomnom/gron","commit_stats":{"total_commits":176,"total_committers":16,"mean_commits":11.0,"dds":"0.11363636363636365","last_synced_commit":"13561bd6339bff18ba571e62313b3f5a6db00111"},"previous_names":[],"tags_count":34,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomnomnom%2Fgron","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomnomnom%2Fgron/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomnomnom%2Fgron/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomnomnom%2Fgron/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tomnomnom","download_url":"https://codeload.github.com/tomnomnom/gron/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253112073,"owners_count":21856069,"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":["cli","json"],"created_at":"2024-07-29T20:00:49.784Z","updated_at":"2025-05-08T22:28:04.616Z","avatar_url":"https://github.com/tomnomnom.png","language":"Go","readme":"# gron\n[![Build Status](https://travis-ci.org/tomnomnom/gron.svg?branch=master)](https://travis-ci.org/tomnomnom/gron)\n\nMake JSON greppable!\n\ngron transforms JSON into discrete assignments to make it easier to `grep` for what you want and see the absolute 'path' to it.\nIt eases the exploration of APIs that return large blobs of JSON but have terrible documentation.\n\n\u003cpre\u003e\n▶ \u003cb\u003egron\u003c/b\u003e \"https://api.github.com/repos/tomnomnom/gron/commits?per_page=1\" | fgrep \"commit.author\"\njson[0].commit.author = {};\njson[0].commit.author.date = \"2016-07-02T10:51:21Z\";\njson[0].commit.author.email = \"mail@tomnomnom.com\";\njson[0].commit.author.name = \"Tom Hudson\";\n\u003c/pre\u003e\n\ngron can work backwards too, enabling you to turn your filtered data back into JSON:\n\u003cpre\u003e\n▶ gron \"https://api.github.com/repos/tomnomnom/gron/commits?per_page=1\" | fgrep \"commit.author\" | \u003cb\u003egron --ungron\u003c/b\u003e\n[\n  {\n    \"commit\": {\n      \"author\": {\n        \"date\": \"2016-07-02T10:51:21Z\",\n        \"email\": \"mail@tomnomnom.com\",\n        \"name\": \"Tom Hudson\"\n      }\n    }\n  }\n]\n\u003c/pre\u003e\n\n\u003e Disclaimer: the GitHub API has fantastic documentation, but it makes for a good example.\n\n## Installation\n\ngron has no runtime dependencies. You can just [download a binary for Linux, Mac, Windows or FreeBSD and run it](https://github.com/tomnomnom/gron/releases).\nPut the binary in your `$PATH` (e.g. in `/usr/local/bin`) to make it easy to use:\n```\n▶ tar xzf gron-linux-amd64-0.1.5.tgz\n▶ sudo mv gron /usr/local/bin/\n```\n\nIf you're a Mac user you can also [install gron via brew](http://braumeister.org/formula/gron):\n```\n▶ brew install gron\n```\n\nOr if you're a Go user you can use `go install`:\n\n```\n▶ go install github.com/tomnomnom/gron@latest\n```\n\nIt's recommended that you alias `ungron` or `norg` (or both!) to `gron --ungron`. Put something like this in your shell profile (e.g. in `~/.bashrc`):\n```\nalias norg=\"gron --ungron\"\nalias ungron=\"gron --ungron\"\n```\nOr you could create a shell script in your $PATH named `ungron` or `norg` to affect all users:\n```\ngron --ungron \"$@\"\n```\n\n## Usage\n\nGet JSON from a file:\n\n```\n▶ gron testdata/two.json \njson = {};\njson.contact = {};\njson.contact.email = \"mail@tomnomnom.com\";\njson.contact.twitter = \"@TomNomNom\";\njson.github = \"https://github.com/tomnomnom/\";\njson.likes = [];\njson.likes[0] = \"code\";\njson.likes[1] = \"cheese\";\njson.likes[2] = \"meat\";\njson.name = \"Tom\";\n```\n\nFrom a URL:\n\n```\n▶ gron http://headers.jsontest.com/\njson = {};\njson.Host = \"headers.jsontest.com\";\njson[\"User-Agent\"] = \"gron/0.1\";\njson[\"X-Cloud-Trace-Context\"] = \"6917a823919477919dbc1523584ba25d/11970839830843610056\";\n```\n\nOr from `stdin`:\n\n```\n▶ curl -s http://headers.jsontest.com/ | gron\njson = {};\njson.Accept = \"*/*\";\njson.Host = \"headers.jsontest.com\";\njson[\"User-Agent\"] = \"curl/7.43.0\";\njson[\"X-Cloud-Trace-Context\"] = \"c70f7bf26661c67d0b9f2cde6f295319/13941186890243645147\";\n```\n\nGrep for something and easily see the path to it:\n\n```\n▶ gron testdata/two.json | grep twitter\njson.contact.twitter = \"@TomNomNom\";\n```\n\ngron makes diffing JSON easy too:\n\n```\n▶ diff \u003c(gron two.json) \u003c(gron two-b.json)\n3c3\n\u003c json.contact.email = \"mail@tomnomnom.com\";\n---\n\u003e json.contact.email = \"contact@tomnomnom.com\";\n```\n\nThe output of `gron` is valid JavaScript:\n\n```\n▶ gron testdata/two.json \u003e tmp.js\n▶ echo \"console.log(json);\" \u003e\u003e tmp.js\n▶ nodejs tmp.js\n{ contact: { email: 'mail@tomnomnom.com', twitter: '@TomNomNom' },\n  github: 'https://github.com/tomnomnom/',\n  likes: [ 'code', 'cheese', 'meat' ],\n  name: 'Tom' }\n```\n\nIt's also possible to obtain the `gron` output as JSON stream via\nthe `--json` switch:\n\n```\n▶ curl -s http://headers.jsontest.com/ | gron --json\n[[],{}]\n[[\"Accept\"],\"*/*\"]\n[[\"Host\"],\"headers.jsontest.com\"]\n[[\"User-Agent\"],\"curl/7.43.0\"]\n[[\"X-Cloud-Trace-Context\"],\"c70f7bf26661c67d0b9f2cde6f295319/13941186890243645147\"]\n```\n\n## ungronning\ngron can also turn its output back into JSON:\n```\n▶ gron testdata/two.json | gron -u\n{\n  \"contact\": {\n    \"email\": \"mail@tomnomnom.com\",\n    \"twitter\": \"@TomNomNom\"\n  },\n  \"github\": \"https://github.com/tomnomnom/\",\n  \"likes\": [\n    \"code\",\n    \"cheese\",\n    \"meat\"\n  ],\n  \"name\": \"Tom\"\n}\n```\n\nThis means you use can use gron with `grep` and other tools to modify JSON:\n```\n▶ gron testdata/two.json | grep likes | gron --ungron\n{\n  \"likes\": [\n    \"code\",\n    \"cheese\",\n    \"meat\"\n  ]\n}\n```\n\nor\n\n\n```\n▶ gron --json testdata/two.json | grep likes | gron  --json --ungron\n{\n  \"likes\": [\n    \"code\",\n    \"cheese\",\n    \"meat\"\n  ]\n}\n```\n\nTo preserve array keys, arrays are padded with `null` when values are missing:\n```\n▶ gron testdata/two.json | grep likes | grep -v cheese\njson.likes = [];\njson.likes[0] = \"code\";\njson.likes[2] = \"meat\";\n▶ gron testdata/two.json | grep likes | grep -v cheese | gron --ungron\n{\n  \"likes\": [\n    \"code\",\n    null,\n    \"meat\"\n  ]\n}\n```\n\nIf you get creative you can do [some pretty neat tricks with gron](ADVANCED.mkd), and\nthen ungron the output back into JSON.\n\n## Get Help\n\n```\n▶ gron --help\nTransform JSON (from a file, URL, or stdin) into discrete assignments to make it greppable\n\nUsage:\n  gron [OPTIONS] [FILE|URL|-]\n\nOptions:\n  -u, --ungron     Reverse the operation (turn assignments back into JSON)\n  -v, --values     Print just the values of provided assignments\n  -c, --colorize   Colorize output (default on tty)\n  -m, --monochrome Monochrome (don't colorize output)\n  -s, --stream     Treat each line of input as a separate JSON object\n  -k, --insecure   Disable certificate validation\n  -j, --json       Represent gron data as JSON stream\n      --no-sort    Don't sort output (faster)\n      --version    Print version information\n\nExit Codes:\n  0\tOK\n  1\tFailed to open file\n  2\tFailed to read input\n  3\tFailed to form statements\n  4\tFailed to fetch URL\n  5\tFailed to parse statements\n  6\tFailed to encode JSON\n\nExamples:\n  gron /tmp/apiresponse.json\n  gron http://jsonplaceholder.typicode.com/users/1 \n  curl -s http://jsonplaceholder.typicode.com/users/1 | gron\n  gron http://jsonplaceholder.typicode.com/users/1 | grep company | gron --ungron\n```\n\n## FAQ\n### Wasn't this written in PHP before?\nYes it was! The original version is [preserved here for posterity](https://github.com/tomnomnom/gron/blob/master/original-gron.php).\n\n### Why the change to Go?\nMostly to remove PHP as a dependency. There's a lot of people who work with JSON who don't have PHP installed.\n\n### Why shouldn't I just use jq?\n[jq](https://stedolan.github.io/jq/) is *awesome*, and a lot more powerful than gron, but with that power comes\ncomplexity. gron aims to make it easier to use the tools you already know, like `grep` and `sed`.\n\ngron's primary purpose is to make it easy to find the path to a value in a deeply nested JSON blob\nwhen you don't already know the structure; much of jq's power is unlocked only once you know that structure.\n","funding_links":[],"categories":["Go","Data Manipulation","Command Line","工具和库","Command-line tools","Go (134)","\u003ca name=\"data\"\u003e\u003c/a\u003edata","Lovely Commands","Weapons","others","Misc","Go (531)","Command Line Tools","命令行工具","🛠️ Productivity","\u003ca name=\"data-management-json\"\u003e\u003c/a\u003eData management - JSON/YAML/etc.","Cryptocurrency","Development","Data Processing","CLI Utilities"],"sub_categories":["JSON","Dependency Management","Golang","Tools","☸️ Kubernetes","Terminal enhancements"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomnomnom%2Fgron","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftomnomnom%2Fgron","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomnomnom%2Fgron/lists"}