0

I have the following data that needs to be transformed into a csv:

 "tfeOrganizations": [
        {
            "org": "MyOrg1",
            "org_admins": [
                "[email protected]", "[email protected]"
            ],
            "org_viewers": [
                "[email protected]","[email protected]"
            ],
            "teams": {
                "genericresources-admins": {
                    "ci_cd_token_regenerate": False,
                    "members": ["[email protected]", "[email protected]"],
                    "workspaces": [
                        [
                            "genericresources-dev",
                            "write"
                        ],
                        [
                            "genericresources-qa",
                            "write"
                        ],
                        [
                            "genericresources-prod",
                            "write"
                        ]
                    ]
                 },
                 "genericresources-contributors": {
                    "ci_cd_token_regenerate": False,
                    "members": ["[email protected]", "[email protected]", "[email protected]"],
                    "workspaces": [
                        [
                            "genericresources-dev",
                            "write"
                        ],
                        [
                            "genericresources-qa",
                            "write"
                        ],
                        [
                            "genericresources-prod",
                            "plan"
                        ]
                    ]
                }
            },
            "workspaces": [
                "genericresources-dev",
                "genericresources-qa",
                "genericresources-prod"
            ]
        }
    ]

The result should be something like this whereas the header is built dynamically based on the longest array for the members across all organisations.

organisation,workspace,org_admin1,org_admin2,org_viewer1,org_viewer2,member1,member2,member3,...

MyOrg1,genericresources-dev,[email protected],[email protected],[email protected],[email protected],firstUser@test,[email protected],...

MyOrg1,genericresources-qa,[email protected],[email protected],[email protected],[email protected],firstUser@test,[email protected],...

MyOrg1,genericresources-prod,[email protected],[email protected],[email protected],[email protected],firstUser@test,[email protected],...

Currently I do not how to tackle this problem.

1
  • I don't think having a dynamic number of pivoted columns is going to be a good idea Commented Jan 12, 2021 at 13:08

1 Answer 1

1

you can create with pandas

example

import pandas as pd

# access your json file
your_json = data['tfeOrganizations']


data_frame = pd.DataFrame(your_json)


data_frame.to_csv('result.csv',data_frame)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.