{"id":21480461,"url":"https://github.com/jsnell/json-to-multicsv","last_synced_at":"2025-06-24T14:34:44.502Z","repository":{"id":45267011,"uuid":"49262242","full_name":"jsnell/json-to-multicsv","owner":"jsnell","description":"Split a JSON file with hierarchical data to multiple CSV files","archived":false,"fork":false,"pushed_at":"2023-02-19T21:54:50.000Z","size":37,"stargazers_count":25,"open_issues_count":2,"forks_count":3,"subscribers_count":4,"default_branch":"master","last_synced_at":"2023-03-12T07:37:36.524Z","etag":null,"topics":["csv","data-conversion","json"],"latest_commit_sha":null,"homepage":"","language":"Perl","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/jsnell.png","metadata":{"files":{"readme":"README.pod","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":"2016-01-08T09:13:59.000Z","updated_at":"2022-10-26T12:04:14.000Z","dependencies_parsed_at":"2022-09-10T08:26:10.118Z","dependency_job_id":null,"html_url":"https://github.com/jsnell/json-to-multicsv","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsnell%2Fjson-to-multicsv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsnell%2Fjson-to-multicsv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsnell%2Fjson-to-multicsv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsnell%2Fjson-to-multicsv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jsnell","download_url":"https://codeload.github.com/jsnell/json-to-multicsv/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226038782,"owners_count":17564046,"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":["csv","data-conversion","json"],"created_at":"2024-11-23T12:15:14.089Z","updated_at":"2024-11-23T12:15:14.691Z","avatar_url":"https://github.com/jsnell.png","language":"Perl","readme":"=pod\n\n=head1 NAME\n\njson-to-multicsv.pl - Split a JSON file with hierarchical data to multiple CSV files\n\n=head1 SYNOPSIS\n\nB\u003cjson-to-multicsv.pl\u003e [ B\u003c--path pathspec:handler\u003e ... ] [ B\u003c--file input-file\u003e ] [ B\u003c--table name\u003e ]\n\n=head1 DESCRIPTION\n\nRead in a JSON file, process it according as specified by the\nB\u003c--path\u003e arguments, and output one or multiple CSV files with the\nsame data in tabular format.\n\n=head1 EXAMPLE\n\nAssuming the following input file:\n\n   {\n       \"item 1\": {\n           \"title\": \"The First Item\",\n           \"genres\": [\"sci-fi\", \"adventure\"],\n           \"rating\": {\n               \"mean\": 9.5,\n               \"votes\": 190\n           }\n       },\n       \"item 2\": {\n           \"title\": \"The Second Item\",\n           \"genres\": [\"history\", \"economics\"],\n           \"rating\": {\n               \"mean\": 7.4,\n               \"votes\": 865\n           },\n           \"sales\": [\n               { \"count\": 76, \"country\": \"us\" },\n               { \"count\": 13, \"country\": \"de\" },\n               { \"count\": 4, \"country\": \"fi\" }\n           ]\n       }\n   }\n\nAnd the following command line flags:\n\n   --path /:table:item\n   --path /*/rating:column\n   --path /*/sales:table:sales\n   --path /*/genres:table:genres\n\nYou'd get the following output files, which can be joined together\nusing the B\u003c*._key\u003e fields.\n\nB\u003citem.csv\u003e:\n\n   item._key,item.rating.mean,item.rating.votes,item.title\n   \"item 1\",9.5,190,\"The First Item\"\n   \"item 2\",7.4,865,\"The Second Item\"\n\nB\u003citem.genres.csv\u003e:\n\n   genres,item._key,item.genres._key\n   sci-fi,\"item 1\",1\n   adventure,\"item 1\",2\n   history,\"item 2\",1\n   economics,\"item 2\",2\n\nB\u003citem.sales.csv\u003e:\n\n   item._key,item.sales._key,sales.count,sales.country\n   \"item 2\",1,76,us\n   \"item 2\",2,13,de\n   \"item 2\",3,4,fi\n\n=head1 OPTIONS\n\n=over 8\n\n=item B\u003c--file\u003e I\u003cinput-file\u003e\n\nRead the JSON input from I\u003cinput-file\u003e.\n\n=item B\u003c--path\u003e I\u003cpathspec\u003e:B\u003ctable\u003e:I\u003cname\u003e\n\nValues matching I\u003cpathspec\u003e should be used to open a new table, with\nthe specified I\u003cname\u003e. The value should be either an object or an\narray. For an object, each field of the object will be used to output\na row in the CSV file corresponding to the new table. The name of the\nfield stored in the B\u003ctablename\u003e._key column. For an array, each\nelement of the array will be used to output a row, with the index of\nthe element (starting from 1) stored in the B\u003ctablename\u003e._key column.\n\nIf multiple tables are nested, the key columns of all outer tables\nwill be also emitted in the inner tables.\n\n=item B\u003c--path\u003e I\u003cpathspec\u003e:B\u003ccolumn\u003e\n\nValues matching I\u003cpathspec\u003e should be used to emit one or more columns\nin the CSV file matching the innermost currently open table, on the\ncurrently open row. (If no table is currently open).\n\nIf the value is a scalar, that value will be output to a column named\nafter the field containing the value as the column name. Note: Scalar\nvalues have an implicit B\u003ccolumn\u003e handler.\n\nIf the value is an object, each of the fields of the object will be used\nto to output a column with the name being based on both the name of that\nfield, and the name of the field that contained the object.\n\n=item B\u003c--path\u003e I\u003cpathspec\u003e:B\u003crow\u003e\n\nThe values matching I\u003cpathspec\u003e will be emitted as new rows. The value\nmust be an object. The name of the field containing the value will be\nignored. This is generally only useful for the toplevel JSON value.\n\n=item B\u003c--path\u003e I\u003cpathspec\u003e:B\u003cignore\u003e\n\nValues matching I\u003cpathspec\u003e (and any of their subvalues) will not\nbe processed at all.\n\n=item B\u003c--table\u003e I\u003cname\u003e\n\nSpecifies the I\u003cname\u003e of the toplevel table, assuming the toplevel\nJSON value is not used to define a table but row data. You will\nprobably want to use a B\u003crow\u003e handler for the toplevel element.\n\n=back\n\n=head1 PATHS AND PATHSPECS\n\nThe path to a specific JSON value is determined by the following\nrules:\n\n- The path of the root element is /\n- The path of a value that's directly contained inside an object\n  is the concatenation of: a) the path of the parent object, b)\n  the '/', c) the field in the object that this value is for.\n- The path of a value that's directly contained inside an array\n  is the concatenation of: a) the path of the parent object, b)\n  the '/', c) the 1-based index in the array of the value.\n\nPaths are matched against with pathspecs. In a pathspec any of the\nelements of the path can instead be replaced with a C\u003c*\u003e, which will\nmatch any element in that position (but not multiple adjacent ones).\nThat is, the pathspec C\u003c/a/*/c\u003e will match C\u003ca/b/c\u003e but not C\u003ca/b/b/c\u003e.\n\n=head1 AUTHOR\n\nJuho Snellman, \u003cjsnell@iki.fi\u003e\n\n=head1 LICENSE\n\nStandard MIT license\n\n=cut\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjsnell%2Fjson-to-multicsv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjsnell%2Fjson-to-multicsv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjsnell%2Fjson-to-multicsv/lists"}