Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a flag to prevent from fields reorder #60

Open
subchen opened this issue Jan 13, 2018 · 2 comments
Open

Add a flag to prevent from fields reorder #60

subchen opened this issue Jan 13, 2018 · 2 comments

Comments

@subchen
Copy link

subchen commented Jan 13, 2018

Current the fields of output struct is sorted, it is not good for me to advanced process.
If the fields order is same with original json format, it is more easy to use for me.

@ChimeraCoder
Copy link
Owner

Could you elaborate on the use case for preserving the order? Field names aren't quite like imports, but in Go, it's generally preferred to keep things in alphabetical order.

@subchen
Copy link
Author

subchen commented Feb 5, 2018

For example: I got a json from https://api.github.com/repos/ChimeraCoder/gojson

{
    "id": 7344683,
    "name": "gojson",
    "full_name": "ChimeraCoder/gojson",
    "owner": {
        "login": "ChimeraCoder",
        "id": 376414,
        "avatar_url": "https://avatars0.githubusercontent.com/u/376414?v=4",
        "gravatar_id": "",
        "url": "https://api.github.com/users/ChimeraCoder",
        "html_url": "https://github.com/ChimeraCoder",
        "followers_url": "https://api.github.com/users/ChimeraCoder/followers",
        "following_url": "https://api.github.com/users/ChimeraCoder/following{/other_user}",
        "gists_url": "https://api.github.com/users/ChimeraCoder/gists{/gist_id}",
        "starred_url": "https://api.github.com/users/ChimeraCoder/starred{/owner}{/repo}",
        "subscriptions_url": "https://api.github.com/users/ChimeraCoder/subscriptions",
        "organizations_url": "https://api.github.com/users/ChimeraCoder/orgs",
        "repos_url": "https://api.github.com/users/ChimeraCoder/repos",
        "events_url": "https://api.github.com/users/ChimeraCoder/events{/privacy}",
        "received_events_url": "https://api.github.com/users/ChimeraCoder/received_events",
        "type": "User",
        "site_admin": false
    },
    "private": false,
    "html_url": "https://github.com/ChimeraCoder/gojson",
    "description": "Automatically generate Go (golang) struct definitions from example JSON",
    "fork": false,
    "url": "https://api.github.com/repos/ChimeraCoder/gojson",
    "forks_url": "https://api.github.com/repos/ChimeraCoder/gojson/forks",
    "keys_url": "https://api.github.com/repos/ChimeraCoder/gojson/keys{/key_id}",
    "collaborators_url": "https://api.github.com/repos/ChimeraCoder/gojson/collaborators{/collaborator}",
    "teams_url": "https://api.github.com/repos/ChimeraCoder/gojson/teams",
    "hooks_url": "https://api.github.com/repos/ChimeraCoder/gojson/hooks",
    "issue_events_url": "https://api.github.com/repos/ChimeraCoder/gojson/issues/events{/number}",
    "events_url": "https://api.github.com/repos/ChimeraCoder/gojson/events",
    "assignees_url": "https://api.github.com/repos/ChimeraCoder/gojson/assignees{/user}",
    "branches_url": "https://api.github.com/repos/ChimeraCoder/gojson/branches{/branch}",
    "tags_url": "https://api.github.com/repos/ChimeraCoder/gojson/tags",
    "blobs_url": "https://api.github.com/repos/ChimeraCoder/gojson/git/blobs{/sha}",
    "git_tags_url": "https://api.github.com/repos/ChimeraCoder/gojson/git/tags{/sha}",
    "git_refs_url": "https://api.github.com/repos/ChimeraCoder/gojson/git/refs{/sha}",
    "trees_url": "https://api.github.com/repos/ChimeraCoder/gojson/git/trees{/sha}",
    "statuses_url": "https://api.github.com/repos/ChimeraCoder/gojson/statuses/{sha}",
    "languages_url": "https://api.github.com/repos/ChimeraCoder/gojson/languages",
    "stargazers_url": "https://api.github.com/repos/ChimeraCoder/gojson/stargazers",
    "contributors_url": "https://api.github.com/repos/ChimeraCoder/gojson/contributors",
    "subscribers_url": "https://api.github.com/repos/ChimeraCoder/gojson/subscribers",
    "subscription_url": "https://api.github.com/repos/ChimeraCoder/gojson/subscription",
    "commits_url": "https://api.github.com/repos/ChimeraCoder/gojson/commits{/sha}",
    "git_commits_url": "https://api.github.com/repos/ChimeraCoder/gojson/git/commits{/sha}",
    "comments_url": "https://api.github.com/repos/ChimeraCoder/gojson/comments{/number}",
    "issue_comment_url": "https://api.github.com/repos/ChimeraCoder/gojson/issues/comments{/number}",
    "contents_url": "https://api.github.com/repos/ChimeraCoder/gojson/contents/{+path}",
    "compare_url": "https://api.github.com/repos/ChimeraCoder/gojson/compare/{base}...{head}",
    "merges_url": "https://api.github.com/repos/ChimeraCoder/gojson/merges",
    "archive_url": "https://api.github.com/repos/ChimeraCoder/gojson/{archive_format}{/ref}",
    "downloads_url": "https://api.github.com/repos/ChimeraCoder/gojson/downloads",
    "issues_url": "https://api.github.com/repos/ChimeraCoder/gojson/issues{/number}",
    "pulls_url": "https://api.github.com/repos/ChimeraCoder/gojson/pulls{/number}",
    "milestones_url": "https://api.github.com/repos/ChimeraCoder/gojson/milestones{/number}",
    "notifications_url": "https://api.github.com/repos/ChimeraCoder/gojson/notifications{?since,all,participating}",
    "labels_url": "https://api.github.com/repos/ChimeraCoder/gojson/labels{/name}",
    "releases_url": "https://api.github.com/repos/ChimeraCoder/gojson/releases{/id}",
    "deployments_url": "https://api.github.com/repos/ChimeraCoder/gojson/deployments",
    "created_at": "2012-12-27T19:10:50Z",
    "updated_at": "2018-02-04T16:46:09Z",
    "pushed_at": "2018-01-30T05:56:31Z",
    "git_url": "git://github.com/ChimeraCoder/gojson.git",
    "ssh_url": "[email protected]:ChimeraCoder/gojson.git",
    "clone_url": "https://github.com/ChimeraCoder/gojson.git",
    "svn_url": "https://github.com/ChimeraCoder/gojson",
    "homepage": "",
    "size": 209,
    "stargazers_count": 1581,
    "watchers_count": 1581,
    "language": "Go",
    "has_issues": true,
    "has_projects": true,
    "has_downloads": true,
    "has_wiki": true,
    "has_pages": false,
    "forks_count": 100,
    "mirror_url": null,
    "archived": false,
    "open_issues_count": 31,
    "license": {
        "key": "gpl-3.0",
        "name": "GNU General Public License v3.0",
        "spdx_id": "GPL-3.0",
        "url": "https://api.github.com/licenses/gpl-3.0"
    },
    "forks": 100,
    "open_issues": 31,
    "watchers": 1581,
    "default_branch": "master",
    "network_count": 100,
    "subscribers_count": 40
}

This json is bigger. It is also not in alphabetical order.

I can have a good view for field priority and similar fields in group.

I think the order in original json is valuable for us, we should follow them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants