{"id":13756291,"url":"https://github.com/astaxie/flatmap","last_synced_at":"2025-05-01T01:31:26.486Z","repository":{"id":57490522,"uuid":"58114388","full_name":"astaxie/flatmap","owner":"astaxie","description":"flatmap transform nested map to flatten map","archived":false,"fork":false,"pushed_at":"2016-05-05T14:55:49.000Z","size":8,"stargazers_count":42,"open_issues_count":0,"forks_count":7,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-06T06:34:55.956Z","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":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/astaxie.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":"2016-05-05T07:58:49.000Z","updated_at":"2024-06-09T10:34:56.000Z","dependencies_parsed_at":"2022-09-08T04:51:41.748Z","dependency_job_id":null,"html_url":"https://github.com/astaxie/flatmap","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/astaxie%2Fflatmap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/astaxie%2Fflatmap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/astaxie%2Fflatmap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/astaxie%2Fflatmap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/astaxie","download_url":"https://codeload.github.com/astaxie/flatmap/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251808486,"owners_count":21647297,"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-08-03T11:00:40.748Z","updated_at":"2025-05-01T01:31:26.125Z","avatar_url":"https://github.com/astaxie.png","language":"Go","readme":"# flatmap\nflatmap transform nested map to flatten map\n\n# How to use?\n\n```\npackage main\n\nimport (\n    \"fmt\"\n\t\"log\"\n\t\"sort\"\n\t\"encoding/json\"\n\n\t\"github.com/astaxie/flatmap\"\n)\n\nvar data =`\n{\n\t\"id\": 1296269,\n\t\"owner\": {\n\t\t\"login\": \"octocat\",\n\t\t\"id\": 1,\n\t\t\"avatar_url\": \"https://github.com/images/error/octocat_happy.gif\",\n\t\t\"gravatar_id\": \"somehexcode\",\n\t\t\"url\": \"https://api.github.com/users/octocat\",\n\t\t\"html_url\": \"https://github.com/octocat\",\n\t\t\"followers_url\": \"https://api.github.com/users/octocat/followers\",\n\t\t\"following_url\": \"https://api.github.com/users/octocat/following{/other_user}\",\n\t\t\"gists_url\": \"https://api.github.com/users/octocat/gists{/gist_id}\",\n\t\t\"starred_url\": \"https://api.github.com/users/octocat/starred{/owner}{/repo}\",\n\t\t\"subscriptions_url\": \"https://api.github.com/users/octocat/subscriptions\",\n\t\t\"organizations_url\": \"https://api.github.com/users/octocat/orgs\",\n\t\t\"repos_url\": \"https://api.github.com/users/octocat/repos\",\n\t\t\"events_url\": \"https://api.github.com/users/octocat/events{/privacy}\",\n\t\t\"received_events_url\": \"https://api.github.com/users/octocat/received_events\",\n\t\t\"type\": \"User\",\n\t\t\"site_admin\": false\n\t},\n\t\"name\": \"Hello-World\",\n\t\"full_name\": \"octocat/Hello-World\",\n\t\"description\": \"This your first repo!\",\n\t\"private\": false,\n\t\"fork\": false,\n\t\"url\": \"https://api.github.com/repos/octocat/Hello-World\",\n\t\"html_url\": \"https://github.com/octocat/Hello-World\",\n\t\"clone_url\": \"https://github.com/octocat/Hello-World.git\",\n\t\"git_url\": \"git://github.com/octocat/Hello-World.git\",\n\t\"ssh_url\": \"git@github.com:octocat/Hello-World.git\",\n\t\"svn_url\": \"https://svn.github.com/octocat/Hello-World\",\n\t\"mirror_url\": \"git://git.example.com/octocat/Hello-World\",\n\t\"homepage\": \"https://github.com\",\n\t\"language\": null,\n\t\"forks_count\": 9,\n\t\"stargazers_count\": 80,\n\t\"watchers_count\": 80,\n\t\"size\": 108,\n\t\"default_branch\": \"master\",\n\t\"open_issues_count\": 0,\n\t\"has_issues\": true,\n\t\"has_wiki\": true,\n\t\"has_downloads\": true,\n\t\"pushed_at\": \"2011-01-26T19:06:43Z\",\n\t\"created_at\": \"2011-01-26T19:01:12Z\",\n\t\"updated_at\": \"2011-01-26T19:14:43Z\",\n\t\"permissions\": {\n\t\t\"admin\": false,\n\t\t\"push\": false,\n\t\t\"pull\": true\n\t},\n\t\"subscribers_count\": 42,\n\t\"organization\": {\n\t\t\"login\": \"octocat\",\n\t\t\"id\": 1,\n\t\t\"avatar_url\": \"https://github.com/images/error/octocat_happy.gif\",\n\t\t\"gravatar_id\": \"somehexcode\",\n\t\t\"url\": \"https://api.github.com/users/octocat\",\n\t\t\"html_url\": \"https://github.com/octocat\",\n\t\t\"followers_url\": \"https://api.github.com/users/octocat/followers\",\n\t\t\"following_url\": \"https://api.github.com/users/octocat/following{/other_user}\",\n\t\t\"gists_url\": \"https://api.github.com/users/octocat/gists{/gist_id}\",\n\t\t\"starred_url\": \"https://api.github.com/users/octocat/starred{/owner}{/repo}\",\n\t\t\"subscriptions_url\": \"https://api.github.com/users/octocat/subscriptions\",\n\t\t\"organizations_url\": \"https://api.github.com/users/octocat/orgs\",\n\t\t\"repos_url\": \"https://api.github.com/users/octocat/repos\",\n\t\t\"events_url\": \"https://api.github.com/users/octocat/events{/privacy}\",\n\t\t\"received_events_url\": \"https://api.github.com/users/octocat/received_events\",\n\t\t\"type\": \"Organization\",\n\t\t\"site_admin\": false\n\t},\n\t\"parent\": {\n\t\t\"id\": 1296269,\n\t\t\"owner\": {\n\t\t\t\"login\": \"octocat\",\n\t\t\t\"id\": 1,\n\t\t\t\"avatar_url\": \"https://github.com/images/error/octocat_happy.gif\",\n\t\t\t\"gravatar_id\": \"somehexcode\",\n\t\t\t\"url\": \"https://api.github.com/users/octocat\",\n\t\t\t\"html_url\": \"https://github.com/octocat\",\n\t\t\t\"followers_url\": \"https://api.github.com/users/octocat/followers\",\n\t\t\t\"following_url\": \"https://api.github.com/users/octocat/following{/other_user}\",\n\t\t\t\"gists_url\": \"https://api.github.com/users/octocat/gists{/gist_id}\",\n\t\t\t\"starred_url\": \"https://api.github.com/users/octocat/starred{/owner}{/repo}\",\n\t\t\t\"subscriptions_url\": \"https://api.github.com/users/octocat/subscriptions\",\n\t\t\t\"organizations_url\": \"https://api.github.com/users/octocat/orgs\",\n\t\t\t\"repos_url\": \"https://api.github.com/users/octocat/repos\",\n\t\t\t\"events_url\": \"https://api.github.com/users/octocat/events{/privacy}\",\n\t\t\t\"received_events_url\": \"https://api.github.com/users/octocat/received_events\",\n\t\t\t\"type\": \"User\",\n\t\t\t\"site_admin\": false\n\t\t},\n\t\t\"name\": \"Hello-World\",\n\t\t\"full_name\": \"octocat/Hello-World\",\n\t\t\"description\": \"This your first repo!\",\n\t\t\"private\": false,\n\t\t\"fork\": true,\n\t\t\"url\": \"https://api.github.com/repos/octocat/Hello-World\",\n\t\t\"html_url\": \"https://github.com/octocat/Hello-World\",\n\t\t\"clone_url\": \"https://github.com/octocat/Hello-World.git\",\n\t\t\"git_url\": \"git://github.com/octocat/Hello-World.git\",\n\t\t\"ssh_url\": \"git@github.com:octocat/Hello-World.git\",\n\t\t\"svn_url\": \"https://svn.github.com/octocat/Hello-World\",\n\t\t\"mirror_url\": \"git://git.example.com/octocat/Hello-World\",\n\t\t\"homepage\": \"https://github.com\",\n\t\t\"language\": null,\n\t\t\"forks_count\": 9,\n\t\t\"stargazers_count\": 80,\n\t\t\"watchers_count\": 80,\n\t\t\"size\": 108,\n\t\t\"default_branch\": \"master\",\n\t\t\"open_issues_count\": 0,\n\t\t\"has_issues\": true,\n\t\t\"has_wiki\": true,\n\t\t\"has_downloads\": true,\n\t\t\"pushed_at\": \"2011-01-26T19:06:43Z\",\n\t\t\"created_at\": \"2011-01-26T19:01:12Z\",\n\t\t\"updated_at\": \"2011-01-26T19:14:43Z\",\n\t\t\"permissions\": {\n\t\t\t\"admin\": false,\n\t\t\t\"push\": false,\n\t\t\t\"pull\": true\n\t\t}\n\t},\n\t\"source\": {\n\t\t\"id\": 1296269,\n\t\t\"owner\": {\n\t\t\t\"login\": \"octocat\",\n\t\t\t\"id\": 1,\n\t\t\t\"avatar_url\": \"https://github.com/images/error/octocat_happy.gif\",\n\t\t\t\"gravatar_id\": \"somehexcode\",\n\t\t\t\"url\": \"https://api.github.com/users/octocat\",\n\t\t\t\"html_url\": \"https://github.com/octocat\",\n\t\t\t\"followers_url\": \"https://api.github.com/users/octocat/followers\",\n\t\t\t\"following_url\": \"https://api.github.com/users/octocat/following{/other_user}\",\n\t\t\t\"gists_url\": \"https://api.github.com/users/octocat/gists{/gist_id}\",\n\t\t\t\"starred_url\": \"https://api.github.com/users/octocat/starred{/owner}{/repo}\",\n\t\t\t\"subscriptions_url\": \"https://api.github.com/users/octocat/subscriptions\",\n\t\t\t\"organizations_url\": \"https://api.github.com/users/octocat/orgs\",\n\t\t\t\"repos_url\": \"https://api.github.com/users/octocat/repos\",\n\t\t\t\"events_url\": \"https://api.github.com/users/octocat/events{/privacy}\",\n\t\t\t\"received_events_url\": \"https://api.github.com/users/octocat/received_events\",\n\t\t\t\"type\": \"User\",\n\t\t\t\"site_admin\": false\n\t\t},\n\t\t\"name\": \"Hello-World\",\n\t\t\"full_name\": \"octocat/Hello-World\",\n\t\t\"description\": \"This your first repo!\",\n\t\t\"private\": false,\n\t\t\"fork\": true,\n\t\t\"url\": \"https://api.github.com/repos/octocat/Hello-World\",\n\t\t\"html_url\": \"https://github.com/octocat/Hello-World\",\n\t\t\"clone_url\": \"https://github.com/octocat/Hello-World.git\",\n\t\t\"git_url\": \"git://github.com/octocat/Hello-World.git\",\n\t\t\"ssh_url\": \"git@github.com:octocat/Hello-World.git\",\n\t\t\"svn_url\": \"https://svn.github.com/octocat/Hello-World\",\n\t\t\"mirror_url\": \"git://git.example.com/octocat/Hello-World\",\n\t\t\"homepage\": \"https://github.com\",\n\t\t\"language\": null,\n\t\t\"forks_count\": 9,\n\t\t\"stargazers_count\": 80,\n\t\t\"watchers_count\": 80,\n\t\t\"size\": 108,\n\t\t\"default_branch\": \"master\",\n\t\t\"open_issues_count\": 0,\n\t\t\"has_issues\": true,\n\t\t\"has_wiki\": true,\n\t\t\"has_downloads\": true,\n\t\t\"pushed_at\": \"2011-01-26T19:06:43Z\",\n\t\t\"created_at\": \"2011-01-26T19:01:12Z\",\n\t\t\"updated_at\": \"2011-01-26T19:14:43Z\",\n\t\t\"permissions\": {\n\t\t\t\"admin\": false,\n\t\t\t\"push\": false,\n\t\t\t\"pull\": true\n\t\t}\n\t}\n}\n`\n\nfunc main() {\n\tvar mp map[string]interface{}\n\tif err := json.Unmarshal([]byte(data), \u0026mp); err != nil {\n\t\tlog.Fatal(err)\n\t}\n\tfm, err := flatmap.Flatten(mp)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\tvar ks []string\n\tfor k:=range fm{\n\t\tks = append(ks,k)\t\t\n\t}\n\tsort.Strings(ks)\n\tfor _,k:=range ks{\n\t\tfmt.Println(k,\":\",fm[k])\n\t}\n\t\n}\n\n```\n\n# output\nKey | Value \n----| -----\nclone_url | https://github.com/octocat/Hello-World.git\ncreated_at | 2011-01-26T19:01:12Z\ndefault_branch | master\ndescription | This your first repo!\nfork | false\nforks_count | 9.000000\nfull_name | octocat/Hello-World\ngit_url | git://github.com/octocat/Hello-World.git\nhas_downloads | true\nhas_issues | true\nhas_wiki | true\nhomepage | https://github.com\nhtml_url | https://github.com/octocat/Hello-World\nid | 1296269.000000\nlanguage |\nmirror_url | git://git.example.com/octocat/Hello-World\nname | Hello-World\nopen_issues_count | 0.000000\norganization.avatar_url | https://github.com/images/error/octocat_happy.gif\norganization.events_url | https://api.github.com/users/octocat/events{/privacy}\norganization.followers_url | https://api.github.com/users/octocat/followers\norganization.following_url | https://api.github.com/users/octocat/following{/other_user}\norganization.gists_url | https://api.github.com/users/octocat/gists{/gist_id}\norganization.gravatar_id | somehexcode\norganization.html_url | https://github.com/octocat\norganization.id | 1.000000\norganization.login | octocat\norganization.organizations_url | https://api.github.com/users/octocat/orgs\norganization.received_events_url | https://api.github.com/users/octocat/received_events\norganization.repos_url | https://api.github.com/users/octocat/repos\norganization.site_admin | false\norganization.starred_url | https://api.github.com/users/octocat/starred{/owner}{/repo}\norganization.subscriptions_url | https://api.github.com/users/octocat/subscriptions\norganization.type | Organization\norganization.url | https://api.github.com/users/octocat\nowner.avatar_url | https://github.com/images/error/octocat_happy.gif\nowner.events_url | https://api.github.com/users/octocat/events{/privacy}\nowner.followers_url | https://api.github.com/users/octocat/followers\nowner.following_url | https://api.github.com/users/octocat/following{/other_user}\nowner.gists_url | https://api.github.com/users/octocat/gists{/gist_id}\nowner.gravatar_id | somehexcode\nowner.html_url | https://github.com/octocat\nowner.id | 1.000000\nowner.login | octocat\nowner.organizations_url | https://api.github.com/users/octocat/orgs\nowner.received_events_url | https://api.github.com/users/octocat/received_events\nowner.repos_url | https://api.github.com/users/octocat/repos\nowner.site_admin | false\nowner.starred_url | https://api.github.com/users/octocat/starred{/owner}{/repo}\nowner.subscriptions_url | https://api.github.com/users/octocat/subscriptions\nowner.type | User\nowner.url | https://api.github.com/users/octocat\nparent.clone_url | https://github.com/octocat/Hello-World.git\nparent.created_at | 2011-01-26T19:01:12Z\nparent.default_branch | master\nparent.description | This your first repo!\nparent.fork | true\nparent.forks_count | 9.000000\nparent.full_name | octocat/Hello-World\nparent.git_url | git://github.com/octocat/Hello-World.git\nparent.has_downloads | true\nparent.has_issues | true\nparent.has_wiki | true\nparent.homepage | https://github.com\nparent.html_url | https://github.com/octocat/Hello-World\nparent.id | 1296269.000000\nparent.language |\nparent.mirror_url | git://git.example.com/octocat/Hello-World\nparent.name | Hello-World\nparent.open_issues_count | 0.000000\nparent.owner.avatar_url | https://github.com/images/error/octocat_happy.gif\nparent.owner.events_url | https://api.github.com/users/octocat/events{/privacy}\nparent.owner.followers_url | https://api.github.com/users/octocat/followers\nparent.owner.following_url | https://api.github.com/users/octocat/following{/other_user}\nparent.owner.gists_url | https://api.github.com/users/octocat/gists{/gist_id}\nparent.owner.gravatar_id | somehexcode\nparent.owner.html_url | https://github.com/octocat\nparent.owner.id | 1.000000\nparent.owner.login | octocat\nparent.owner.organizations_url | https://api.github.com/users/octocat/orgs\nparent.owner.received_events_url | https://api.github.com/users/octocat/received_events\nparent.owner.repos_url | https://api.github.com/users/octocat/repos\nparent.owner.site_admin | false\nparent.owner.starred_url | https://api.github.com/users/octocat/starred{/owner}{/repo}\nparent.owner.subscriptions_url | https://api.github.com/users/octocat/subscriptions\nparent.owner.type | User\nparent.owner.url | https://api.github.com/users/octocat\nparent.permissions.admin | false\nparent.permissions.pull | true\nparent.permissions.push | false\nparent.private | false\nparent.pushed_at | 2011-01-26T19:06:43Z\nparent.size | 108.000000\nparent.ssh_url | git@github.com:octocat/Hello-World.git\nparent.stargazers_count | 80.000000\nparent.svn_url | https://svn.github.com/octocat/Hello-World\nparent.updated_at | 2011-01-26T19:14:43Z\nparent.url | https://api.github.com/repos/octocat/Hello-World\nparent.watchers_count | 80.000000\npermissions.admin | false\npermissions.pull | true\npermissions.push | false\nprivate | false\npushed_at | 2011-01-26T19:06:43Z\nsize | 108.000000\nsource.clone_url | https://github.com/octocat/Hello-World.git\nsource.created_at | 2011-01-26T19:01:12Z\nsource.default_branch | master\nsource.description | This your first repo!\nsource.fork | true\nsource.forks_count | 9.000000\nsource.full_name | octocat/Hello-World\nsource.git_url | git://github.com/octocat/Hello-World.git\nsource.has_downloads | true\nsource.has_issues | true\nsource.has_wiki | true\nsource.homepage | https://github.com\nsource.html_url | https://github.com/octocat/Hello-World\nsource.id | 1296269.000000\nsource.language |\nsource.mirror_url | git://git.example.com/octocat/Hello-World\nsource.name | Hello-World\nsource.open_issues_count | 0.000000\nsource.owner.avatar_url | https://github.com/images/error/octocat_happy.gif\nsource.owner.events_url | https://api.github.com/users/octocat/events{/privacy}\nsource.owner.followers_url | https://api.github.com/users/octocat/followers\nsource.owner.following_url | https://api.github.com/users/octocat/following{/other_user}\nsource.owner.gists_url | https://api.github.com/users/octocat/gists{/gist_id}\nsource.owner.gravatar_id | somehexcode\nsource.owner.html_url | https://github.com/octocat\nsource.owner.id | 1.000000\nsource.owner.login | octocat\nsource.owner.organizations_url | https://api.github.com/users/octocat/orgs\nsource.owner.received_events_url | https://api.github.com/users/octocat/received_events\nsource.owner.repos_url | https://api.github.com/users/octocat/repos\nsource.owner.site_admin | false\nsource.owner.starred_url | https://api.github.com/users/octocat/starred{/owner}{/repo}\nsource.owner.subscriptions_url | https://api.github.com/users/octocat/subscriptions\nsource.owner.type | User\nsource.owner.url | https://api.github.com/users/octocat\nsource.permissions.admin | false\nsource.permissions.pull | true\nsource.permissions.push | false\nsource.private | false\nsource.pushed_at | 2011-01-26T19:06:43Z\nsource.size | 108.000000\nsource.ssh_url | git@github.com:octocat/Hello-World.git\nsource.stargazers_count | 80.000000\nsource.svn_url | https://svn.github.com/octocat/Hello-World\nsource.updated_at | 2011-01-26T19:14:43Z\nsource.url | https://api.github.com/repos/octocat/Hello-World\nsource.watchers_count | 80.000000\nssh_url | git@github.com:octocat/Hello-World.git\nstargazers_count | 80.000000\nsubscribers_count | 42.000000\nsvn_url | https://svn.github.com/octocat/Hello-World\nupdated_at | 2011-01-26T19:14:43Z\nurl | https://api.github.com/repos/octocat/Hello-World\nwatchers_count | 80.000000","funding_links":[],"categories":["Go"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fastaxie%2Fflatmap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fastaxie%2Fflatmap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fastaxie%2Fflatmap/lists"}