{"id":15432942,"url":"https://github.com/simonw/flatten-single-item-arrays","last_synced_at":"2025-04-19T17:52:02.238Z","repository":{"id":57430933,"uuid":"342277531","full_name":"simonw/flatten-single-item-arrays","owner":"simonw","description":"Given a JSON list of objects, flatten any keys which always contain single item arrays to just a single value","archived":false,"fork":false,"pushed_at":"2021-02-25T14:50:42.000Z","size":8,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-10-18T07:53:30.992Z","etag":null,"topics":["airtable-api","json"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/simonw.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}},"created_at":"2021-02-25T14:49:14.000Z","updated_at":"2023-10-30T15:09:26.000Z","dependencies_parsed_at":"2022-08-28T23:02:03.551Z","dependency_job_id":null,"html_url":"https://github.com/simonw/flatten-single-item-arrays","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonw%2Fflatten-single-item-arrays","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonw%2Fflatten-single-item-arrays/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonw%2Fflatten-single-item-arrays/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonw%2Fflatten-single-item-arrays/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/simonw","download_url":"https://codeload.github.com/simonw/flatten-single-item-arrays/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249753088,"owners_count":21320664,"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":["airtable-api","json"],"created_at":"2024-10-01T18:29:30.801Z","updated_at":"2025-04-19T17:52:02.216Z","avatar_url":"https://github.com/simonw.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# flatten-single-item-arrays\n\n[![PyPI](https://img.shields.io/pypi/v/flatten-single-item-arrays.svg)](https://pypi.org/project/flatten-single-item-arrays/)\n[![Changelog](https://img.shields.io/github/v/release/simonw/flatten-single-item-arrays?include_prereleases\u0026label=changelog)](https://github.com/simonw/flatten-single-item-arrays/releases)\n[![Tests](https://github.com/simonw/flatten-single-item-arrays/workflows/Test/badge.svg)](https://github.com/simonw/flatten-single-item-arrays/actions?query=workflow%3ATest)\n[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/simonw/flatten-single-item-arrays/blob/master/LICENSE)\n\nGiven a JSON list of objects, flatten any keys which always contain single item arrays to just a single value\n\n## Installation\n\nInstall this tool using `pip`:\n\n    $ pip install flatten-single-item-arrays\n\n## Usage\n\nThis will output the rewritten JSON:\n\n    $ flatten-single-item-arrays input.json\n\nYou can save it to a file like this:\n\n    $ flatten-single-item-arrays input.json \u003e output.json\n\nUse `--debug` to see extra debugging information displayed on standard error:\n\n    $ flatten-single-item-arrays input.json --debug \u003e output.json\n    Item count: 2\n    count_of_single_item_lists\n    {\n        \"foo\": 2\n    }\n    count_of_present_keys\n    {\n        \"foo\": 2,\n        \"bar\": 2\n    }\n    keys_to_reformat:\n    - foo\n\n## What this does\n\nThis tool accepts the path to a JSON file and outputs a modified version of that JSON file where any keys that are *always* single item lists are rewritten to a single value.\n\nFor example, the following input:\n\n```json\n[\n    {\n        \"foo\": [\n            \"bar\"\n        ],\n        \"bar\": 5\n    },\n    {\n        \"foo\": [\n            \"baz\"\n        ],\n        \"bar\": 6\n    }\n]\n```\n\nWill be transformed to this:\n\n```json\n[\n    {\n        \"foo\": \"bar\",\n        \"bar\": 5\n    },\n    {\n        \"foo\": \"baz\",\n        \"bar\": 6\n    }\n]\n```\n\nI built this to help work with data from the Airtable API, which often contains this single-item-list pattern.\n\n## Development\n\nTo contribute to this tool, first checkout the code. Then create a new virtual environment:\n\n    cd flatten-single-item-arrays\n    python -mvenv venv\n    source venv/bin/activate\n\nOr if you are using `pipenv`:\n\n    pipenv shell\n\nNow install the dependencies and tests:\n\n    pip install -e '.[test]'\n\nTo run the tests:\n\n    pytest\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimonw%2Fflatten-single-item-arrays","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimonw%2Fflatten-single-item-arrays","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimonw%2Fflatten-single-item-arrays/lists"}