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


Messages In This Thread
json.dumps output error in python3 - by prayuktibid - Jan-21-2020, 06:23 AM
RE: json.dumps output error in python3 - by buran - Jan-21-2020, 06:36 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  json loads throwing error mpsameer 8 708 Jan-23-2024, 07:04 AM
Last Post: deanhystad
  Error with output djprasanna 1 552 Nov-28-2023, 06:40 PM
Last Post: deanhystad
  Understanding and debugging memory error crashes with python3.10.10 Arkaik 5 2,114 Apr-18-2023, 03:22 AM
Last Post: Larz60+
  json decoding error deneme2 10 3,680 Mar-22-2023, 10:44 PM
Last Post: deanhystad
  python requests library .JSON() error mHosseinDS86 6 3,453 Dec-19-2022, 08:28 PM
Last Post: deanhystad
  Read nested data from JSON - Getting an error marlonbown 5 1,383 Nov-23-2022, 03:51 PM
Last Post: snippsat
  geojson to json --missing multiple row output yoshi 9 2,794 Mar-06-2022, 08:34 PM
Last Post: snippsat
  JSON Decode error when using API to create dataframe Rubstiano7 4 2,961 Jan-11-2021, 07:52 PM
Last Post: buran
Bug maximum recursion depth exceeded while calling a Python object error in python3 Prezess 4 3,782 Aug-02-2020, 02:21 PM
Last Post: deanhystad
  import yaml error for python3 maiya 4 13,166 Jul-15-2020, 06:07 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

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