skip to Main Content

Python format json for saving to file

My data looks like this: Key1: [Key2:[{},{},...{}]] The code something like this: dict_={} dict_['Key2']=all_items dict_fin={} dict_fin['Ke1']=[dict_] df=pd.DataFrame(dict_fin) df.to_json(filepath, orient="records",lines=True) I would like to have saved json like this: { "Key1": [{"Key2" : [{},{},...,{}]}] } Instead, I get it like this:…

VIEW QUESTION

flatten a json using json_normalize

I have the following nested dictionary with lists inside: [{ "id": 467, "status": 2, "leavePeriod": { "owner": { "employeeNumber": "2620", "firstName": "fn_467", "lastName": "ln_467" }, "ownerId": 46, "leaves": [ { "leaveAccount": { "id": 1121, "name": "Vacation days 2021/2022", "url": "https://some_link/1121"…

VIEW QUESTION

Json – Python flatten a dictionary column

It should be a simple line of code using pd.json_normalize function but it's working only with a single string and it's not batch processing my whole column Orginial dataframe df['addresses'][0] [{'addressLine1': '124 Main Street', 'addressLine2': '', 'addressLine3': '', 'city': 'Portland',…

VIEW QUESTION

Create JSON object literal only if value is not null

I wrote a script which updates some fields in a database via an API. fields = [{ "fieldId": "101", "fieldValues": [{"value": df["A"].item()}]}, { "fieldId": "102", "fieldValues": [{"value": df["B"].item()}]}, { "fieldId": "103", "fieldValues": [{"value": df["C"].item()}]}, { "fieldId": "104", "fieldValues": [{"value": df["D"].item()}]},…

VIEW QUESTION
Back To Top
Search