#๐Ÿ”’ Combine multiple JSON Strings

14 messages ยท Page 1 of 1 (latest)

lavish adder
#

Hello there,

I have an excel file which has multiple tabs. For each tab, I do some minor optimizations and finally I convert each tab to a JSON string. What I want to do is merge all these JSON strings together, so I only would have 1 output.json.

This is the current code:

base_json = []

for i in range(4):
    df = pd.read_excel(path)
    # Some optimizations here

    json_str = df.to_json(orient='records')    
    base_json += json.loads(json_str)
    
base_json

When I try to set the output to a JSON file, it screams errors about not being converted correctly. See the image as an example. Can maybe someone tell me on how i can fix this?

https://likegeeks.com/merge-json-arrays-python/

Learn to merge JSON arrays in Python with this tutorial. Discover techniques using + operator, reduce(), and jsonmerge for efficient data handling.

hoary kestrelBOT
#

@lavish adder

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

woeful cloak
lavish adder
#

Oh really? Ok, then I would try that

woeful cloak
#

yeah definitely

#

Do the columns all match up?

lavish adder
#

Yeah, I only need the first 4 tabs.

#

Oh wait, 1 tab doesn't. Its a calculation luckily, so i will remove it.

#

I do have a tiny question: All 4 tabs need to remove row 2 & 3. How can I do this?

#

Would this suggest I need to do for each sheet manually or is there a more simple way?

lavish adder
#

Got it!

hoary kestrelBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.