Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
unable to indent json data
#1
I am trying to print the JSON with proper indentation and sorted keys, but it throws an error.

Need help to fix this

Complete code :

>>> import json
>>> import time
>>> for n in range(1, 10):
...   data = {'id': n, 't': float("%.3f" % time.time()), 'interest':['photo','tt']}
...   jsonData=json.dumps(data)
...   data = jsonData.encode('utf-8')
...   print(data (indent=4, sort_keys=True))
...
Error:
Traceback (most recent call last): File "<stdin>", line 5, in <module> TypeError: 'bytes' object is not callable >>>
Reply


Messages In This Thread
unable to indent json data - by dataplumber - Oct-22-2019, 01:26 PM
RE: unable to indent json data - by buran - Oct-22-2019, 01:34 PM
RE: unable to indent json data - by dataplumber - Oct-22-2019, 01:38 PM
RE: unable to indent json data - by buran - Oct-22-2019, 01:45 PM
RE: unable to indent json data - by dataplumber - Oct-22-2019, 01:55 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  encrypt data in json file help jacksfrustration 1 394 Mar-28-2024, 05:16 PM
Last Post: deanhystad
  getting unexpected indent errors trying to move cells up jensengt 4 972 Jun-28-2023, 12:05 PM
Last Post: deanhystad
  xml indent SubElements (wrapping) with multiple strings ctrldan 2 1,680 Jun-09-2023, 08:42 PM
Last Post: ctrldan
  Read nested data from JSON - Getting an error marlonbown 5 1,521 Nov-23-2022, 03:51 PM
Last Post: snippsat
  Reading Data from JSON tpolim008 2 1,189 Sep-27-2022, 06:34 PM
Last Post: Larz60+
  Unable to request image from FORM Data usman 0 1,054 Aug-18-2022, 06:23 PM
Last Post: usman
  Convert nested sample json api data into csv in python shantanu97 3 3,040 May-21-2022, 01:30 PM
Last Post: deanhystad
  Struggling with Juggling JSON Data SamWatt 7 2,064 May-09-2022, 02:49 AM
Last Post: snippsat
  IndentationError: unexpected indent dee 3 2,492 May-02-2022, 02:15 AM
Last Post: dee
  json api data parsing elvis 0 977 Apr-21-2022, 11:59 PM
Last Post: elvis

Forum Jump:

User Panel Messages

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