{"id":22748532,"url":"https://github.com/pitr/fj","last_synced_at":"2025-09-01T20:34:22.572Z","repository":{"id":57619442,"uuid":"381846190","full_name":"pitr/fj","owner":"pitr","description":"Flatten JSON","archived":false,"fork":false,"pushed_at":"2023-12-31T16:26:09.000Z","size":190,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-14T12:05:35.639Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/pitr.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":"2021-06-30T22:19:39.000Z","updated_at":"2023-11-01T12:11:21.000Z","dependencies_parsed_at":"2024-06-20T13:07:18.703Z","dependency_job_id":"17c9e2f7-2809-4d70-abaf-6857c4c28e86","html_url":"https://github.com/pitr/fj","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/pitr%2Ffj","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pitr%2Ffj/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pitr%2Ffj/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pitr%2Ffj/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pitr","download_url":"https://codeload.github.com/pitr/fj/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248877984,"owners_count":21176243,"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":[],"created_at":"2024-12-11T03:33:15.562Z","updated_at":"2025-04-14T12:05:40.204Z","avatar_url":"https://github.com/pitr.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fj\n\nFlatten your JSON.\n\n`fj` flattens JSON into a value and its full path per line, so data can be worked on using UNIX tools such as grep/awk/cut/etc.\n\n\u003cpre\u003e\n❯ curl -s \"https://api.github.com/repos/golang/go/commits?per_page=1\" | \u003cb\u003efj\u003c/b\u003e | grep commit.author\njson[0].commit.author.name  \"Josh Bleecher Snyder\"\njson[0].commit.author.email \"josharian@gmail.com\"\njson[0].commit.author.date  \"2021-06-30T16:44:30Z\"\n\u003c/pre\u003e\n\nfj can un-flatten too, which is useful to get a subset of JSON:\n\n\u003cpre\u003e\n❯ curl -s \"https://api.github.com/repos/golang/go/commits?per_page=1\" | fj | grep commit.author | \u003cb\u003efj -u\u003c/b\u003e | jq\n[\n  {\n    \"commit\": {\n      \"author\": {\n        \"name\": \"Josh Bleecher Snyder\",\n        \"email\": \"josharian@gmail.com\",\n        \"date\": \"2021-06-30T16:44:30Z\"\n      }\n    }\n  }\n]\n\u003c/pre\u003e\n\n## Installation\n\n1. Download [latest release for Linux, Mac, Windows or FreeBSD](https://github.com/pitr/fj/releases),\n2. Put the binary in your `$PATH` (e.g. in `/usr/local/bin`) to make it easy to use:\n\nAlternatively, if you have Go compiler:\n\n```\n❯ go install pitr.ca/fj@latest # OR\n❯ go get -u pitr.ca/fj         # legacy way\n```\n\n## Usage\n\nFlatten JSON file or stdin:\n\n```\n❯ fj file.json\n❯ cat file.json | fj\n```\n\nOr many JSON files. Use `-s` or `--stream` to treat input as a stream of JSON documents:\n\n```\n❯ fj -s file1.json file2.json file3.json\n```\n\nUse `grep` to search, `diff \u003c(fj file1.json) \u003c(fj file2.json)` to diff, and other  tools such as `awk/sort/uniq/fzf`.\n\n## FAQ\n\n### Why shouldn't I just use gron?\n\n[gron](https://github.com/tomnomnom/gron) is a very similar tool. However, `fj` is different from it in a few key ways:\n\n- fj does not keep the whole JSON object in memory, which allows it to be 10-20 times faster than gron.\n\n  ```\n  ❯ hyperfine --warmup 5 'gron testdata/big.json' 'fj testdata/big.json'\n  Benchmark #1: gron testdata/big.json\n    Time (mean ± σ):     136.2 ms ±   1.9 ms    [User: 57.1 ms, System: 97.2 ms]\n    Range (min … max):   132.9 ms … 140.2 ms    21 runs\n\n  Benchmark #2: fj testdata/big.json\n    Time (mean ± σ):       9.1 ms ±   0.9 ms    [User: 4.9 ms, System: 2.4 ms]\n    Range (min … max):     7.8 ms …  12.2 ms    203 runs\n\n  Summary\n    'fj testdata/big.json' ran\n     14.93 ± 1.48 times faster than 'gron testdata/big.json'\n  ```\n\n- `fj` does not preserve array structures by padding with null.\n\n  ```\n  ❯ echo '[1,2,3,4,5]' | gron | grep 5 | gron -u\n  [\n     null,\n     null,\n     null,\n     null,\n     5\n  ]\n  ❯ echo '[1,2,3,4,5]' | fj | grep 5 | fj -u\n  [5]\n  ```\n\n- `fj` does not try to convert JSON into valid JavaScript that can be pasted into JS console. There are no extra semicolons and array/object initializations.\n\n### Why shouldn't I just use jq?\n[jq](https://stedolan.github.io/jq/) is a great and powerful tool with its own language. `fj` simply flattens (and un-flattens) JSON, and is expected to integrate with existing tools.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpitr%2Ffj","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpitr%2Ffj","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpitr%2Ffj/lists"}