Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
json.dumps list output
#11
I'm not sure I understand what your end goal is.
Is it to convert the dictionary to a list?
Reply
#12
(Mar-16-2020, 09:13 AM)qurr Wrote: Well, um, I just need this format to complete the task. This is what the "customer" wants.

This seems a bit strange really. JSON is meant to be passed between machines, so formatting makes no difference to them. If a human wants to read it, surely they can use whatever pretty printing tools exist. If you've been told specifically to format it that way for an assignment, it sounds like emphasis is being placed on the wrong things.
Reply
#13
(Mar-16-2020, 12:41 AM)qurr Wrote: Is it possible in python 3.8 to print list in one line rather than printing each item on new line via json.dumps? Are there any other json libraries that can do it?
I'm confused, it seems like that's the default behavior?
Output:
>>> import json >>> json.dumps([ ... [1, 2], ... [3, 4], ... ]) '[[1, 2], [3, 4]]'
(Mar-17-2020, 05:44 AM)ndc85430 Wrote: This seems a bit strange really. JSON is meant to be passed between machines, so formatting makes no difference to them.
I disagree strongly with this. Python's json.dumps method even has functionality for changing how the data looks, even though the dicts would be equal in Python (off the top of my hey, indent and sort_keys come to mind).

If the customer wants something, then that's what they want. End of story. I wish I could help, I'm just unclear on what the OP actually wants in spite of all the posts already.
Feel like you're not getting the answers you want? Checkout the help/rules for things like what to include/not include in a post, how to use code tags, how to ask smart questions, and more.

Pro-tip - there's an inverse correlation between the number of lines of code posted and my enthusiasm for helping with a question :)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question convert unlabeled list of tuples to json (string) masterAndreas 4 646 Apr-27-2021, 10:35 AM
Last Post: masterAndreas
  How to append to list a function output? rama27 5 864 Aug-24-2020, 10:53 AM
Last Post: DeaD_EyE
  API JSON response missing list gives keyerror rolfmadsen 3 819 Mar-28-2020, 10:12 AM
Last Post: buran
  If item in list = true, Output = xx kroh 0 572 Feb-19-2020, 09:17 AM
Last Post: kroh
  Not Getting the Desired value using json.dumps saurabh210 0 604 Feb-03-2020, 06:48 PM
Last Post: saurabh210
  json.dumps output error in python3 prayuktibid 2 851 Jan-21-2020, 06:41 AM
Last Post: prayuktibid
  Output to a json file problem Netcode 3 1,198 Nov-22-2019, 01:44 AM
Last Post: Skaperen
  Difference in list output OokaydO 6 1,152 Nov-09-2019, 12:33 AM
Last Post: OokaydO
  json.load causing IndexError: list index out of range WallyZ 5 2,775 May-20-2019, 01:11 PM
Last Post: WallyZ
  json.dumps to keep dictionary keys batchenr 1 762 May-14-2019, 11:17 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020