Python Forum
json.dumps output error in python3
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
json.dumps output error in python3
#1
I am trying to send a dict file in JSON fromat usin "ujson.dumps" method to local http server. After executing ujson.dumps the output get changes.

This is my code
import ujson file ={ "success": true, "status_code": 200, "version": "1.2.0003", "path": "/get_capture_options", "method": "GET", "capture_options": [ { "width": 1920, "framerate": 30, "height": 1080 }, { "width": 1280, "framerate": 30, "height": 720 }, { "width": 1280, "framerate": 60, "height": 720 }, { "width": 640, "framerate": 30, "height": 480 }, { "width": 640, "framerate": 60, "height": 480 }, { "width": 640, "framerate": 90, "height": 480 } ] } file2 = ujson.dumps(file).encode('utf-8') print(file2)
This is the output:
Quote: b'{"success":true,
"status_code":200,
"method":"GET",
"path":"\\/get_capture_options",
"version":"1.2.0003",
"capture_options":[{"width":1920,"height":1080,"framerate":30},
{"width":1280,"height":720,"framerate":30},
{"width":1280,"height":720,"framerate":60},
{"width":640,"height":480,"framerate":30},
{"width":640,"height":480,"framerate":60},
{"width":640,"height":480,"framerate":90}]}'
You can seen in path parameter the "\\" added. Why is this happening? how to solve this? Please help.
Reply
#2
Looking at the docs, there is option escape_forward_slashes, which controls whether forward slashes (/) are escaped. Default is True.

If you are going to use third-party package, at least make an effort to read the [relevant part of] the docs
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
Thank you
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  json loads throwing error mpsameer 8 7,766 Jan-23-2024, 07:04 AM
Last Post: deanhystad
  Error with output djprasanna 1 1,624 Nov-28-2023, 06:40 PM
Last Post: deanhystad
  Understanding and debugging memory error crashes with python3.10.10 Arkaik 5 6,511 Apr-18-2023, 03:22 AM
Last Post: Larz60+
  json decoding error deneme2 10 10,543 Mar-22-2023, 10:44 PM
Last Post: deanhystad
  python requests library .JSON() error mHosseinDS86 6 9,675 Dec-19-2022, 08:28 PM
Last Post: deanhystad
  Read nested data from JSON - Getting an error marlonbown 5 3,782 Nov-23-2022, 03:51 PM
Last Post: snippsat
  geojson to json --missing multiple row output yoshi 9 6,678 Mar-06-2022, 08:34 PM
Last Post: snippsat
  JSON Decode error when using API to create dataframe Rubstiano7 4 5,871 Jan-11-2021, 07:52 PM
Last Post: buran
  attribute error instead of correct output MaartenRo 2 3,577 Aug-28-2020, 10:22 AM
Last Post: Larz60+
Bug maximum recursion depth exceeded while calling a Python object error in python3 Prezess 4 7,845 Aug-02-2020, 02:21 PM
Last Post: deanhystad

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020
This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.