0

Here is a sample of json data I created from defaultdict in python.

[{
    "company": [
        "ABCD"
    ],
    "fullname": [
        "Bruce Lamont",
        "Ariel Zilist",
        "Bruce Lamont",
        "Bobby Ramirez"
    ],
    "position": [
        " The Hesh",
        " Server",
        " HESH",
        " Production Assistant"
    ],
    "profile_url": [
        "http://www.url1.com",
        "http://www.url2.com",
        "http://www.url3.com",
        "http://www.url4.com",
    ]
}]

I realized I made a mistake creating such list. json.loads() gives this error

Error

Expecting value: line 1 column 1 (char 0).

I want something like this.

[{
    "company": [
        "name": "THALIA HALL",
        "employee": {
            fullname: "emp_name",
            "position": "position",
            profile: "url"
        },
        {
            fullname: "emp_name",
            "position": "position",
            profile: "url"
        }
    ]
}]

How can I solve this problem? I need to do this on python.

2 Answers 2

1

you are adding an extra comma in the end for profile_url array. The proper json should be

[{
    "company": [
        "ABCD"
    ],
    "fullname": [
        "Bruce Lamont",
        "Ariel Zilist",
        "Bruce Lamont",
        "Bobby Ramirez"
    ],
    "position": [
        " The Hesh",
        " Server",
        " HESH",
        " Production Assistant"
    ],
    "profile_url": [
        "http://www.url1.com",
        "http://www.url2.com",
        "http://www.url3.com",
        "http://www.url4.com"
    ]
}]

Use https://jsonformatter.curiousconcept.com/ to check for JSON formatting errors next time.

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

Comments

0
import json

j  = '[{"company":["ABCD"],"fullname":["Bruce Lamont","Ariel Zilist","Bruce Lamont","Bobby Ramirez"],"position":[" The Hesh"," Server"," HESH"," Production Assistant"],"profile_url":["http://www.url1.com","http://www.url2.com","http://www.url3.com","http://www.url4.com"]}]'


json_obj = json.loads(j)

you have your JSON as object and now you can user for making csv

1 Comment

I have around 2000 company info stored in a json file as shown in first snippet in my question. Actually I want to convert it into csv. How can I do that?

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.