Json format error /u/Spaghettix_ Python Education

Hi,

sorry if it’s a stupid question, but I never worked with JSON before and I’m struggling with something.

So, I have a UDP communication with sensors sending the data to an IP. The code is this :

import socket import json UDP_IP = "192.168.225.115" UDP_PORT = 5300 max = 10 sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) sock.bind((UDP_IP, UDP_PORT)) print(f"Listening for UDP packets on {UDP_IP}:{UDP_PORT}...") for i in range(0,max): data, addr = sock.recvfrom(2048) parsed_data = json.loads(data) 

And I get this error :

Traceback (most recent call last): File "C:UsersADPFISTEPycharmProjectsSewioAPIUDP sockets saving.py", line 18, in <module> parsed_data = json.loads(data) ^^^^^^^^^^^^^^^^ File "C:Program FilesWindowsAppsPythonSoftwareFoundation.Python.3.12_3.12.2288.0_x64__qbz5n2kfra8p0Libjson__init__.py", line 346, in loads return _default_decoder.decode(s) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:Program FilesWindowsAppsPythonSoftwareFoundation.Python.3.12_3.12.2288.0_x64__qbz5n2kfra8p0Libjsondecoder.py", line 341, in decode raise JSONDecodeError("Extra data", s, end) json.decoder.JSONDecodeError: Extra data: line 1 column 943 (char 942) 

What I don’t understand is that my JSON file is a good format, here is the file :

Any idea why it doesn’t work ?

{ "id": "8", "address": "0x24046650686A", "uuid": "2a886974-b235-11ef-9212-24046650686a", "datastreams": [ { "id": "posX", "current_value": " 1.16", "at": "2025-01-13 09:17:18.607" }, { "id": "posY", "current_value": " 3.59", "at": "2025-01-13 09:17:18.607" }, { "id": "clr", "current_value": " 0.32", "at": "2025-01-13 09:17:18.607" }, { "id": "numberOfAnchors", "current_value": "4", "at": "2025-01-13 09:17:18.607" } ], "extended_tag_position": { "master": "803428289F89", "seq": 5, "calculation": { "at": "2025-01-13 09:17:18.631" }, "corrected": false, "raw_position": { "posX": "1.26", "posY": "3.55", "at": "2025-01-13 09:17:18.607", "numberOfAnchors": "4", "clr": "0.32" }, "slaves": [ { "address": "80342827ACA6", "time": 0.609190425373519, "fp": -82.86, "rssi": -79.13 }, { "address": "80342827C257", "time": 0.609190436174244, "fp": -89.28, "rssi": -83.23 }, { "address": "80342827A461", "time": 0.609190439330494, "fp": -96.61, "rssi": -87.52 }, { "address": "803428289F89", "time": 0.609190434006911, "fp": -98.36, "rssi": -86.72 } ] } } 

submitted by /u/Spaghettix_
[link] [comments]

​r/learnpython Hi, sorry if it’s a stupid question, but I never worked with JSON before and I’m struggling with something. So, I have a UDP communication with sensors sending the data to an IP. The code is this : import socket import json UDP_IP = “192.168.225.115” UDP_PORT = 5300 max = 10 sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) sock.bind((UDP_IP, UDP_PORT)) print(f”Listening for UDP packets on {UDP_IP}:{UDP_PORT}…”) for i in range(0,max): data, addr = sock.recvfrom(2048) parsed_data = json.loads(data) And I get this error : Traceback (most recent call last): File “C:UsersADPFISTEPycharmProjectsSewioAPIUDP sockets saving.py”, line 18, in <module> parsed_data = json.loads(data) ^^^^^^^^^^^^^^^^ File “C:Program FilesWindowsAppsPythonSoftwareFoundation.Python.3.12_3.12.2288.0_x64__qbz5n2kfra8p0Libjson__init__.py”, line 346, in loads return _default_decoder.decode(s) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File “C:Program FilesWindowsAppsPythonSoftwareFoundation.Python.3.12_3.12.2288.0_x64__qbz5n2kfra8p0Libjsondecoder.py”, line 341, in decode raise JSONDecodeError(“Extra data”, s, end) json.decoder.JSONDecodeError: Extra data: line 1 column 943 (char 942) What I don’t understand is that my JSON file is a good format, here is the file : Any idea why it doesn’t work ? { “id”: “8”, “address”: “0x24046650686A”, “uuid”: “2a886974-b235-11ef-9212-24046650686a”, “datastreams”: [ { “id”: “posX”, “current_value”: ” 1.16″, “at”: “2025-01-13 09:17:18.607” }, { “id”: “posY”, “current_value”: ” 3.59″, “at”: “2025-01-13 09:17:18.607” }, { “id”: “clr”, “current_value”: ” 0.32″, “at”: “2025-01-13 09:17:18.607” }, { “id”: “numberOfAnchors”, “current_value”: “4”, “at”: “2025-01-13 09:17:18.607” } ], “extended_tag_position”: { “master”: “803428289F89”, “seq”: 5, “calculation”: { “at”: “2025-01-13 09:17:18.631” }, “corrected”: false, “raw_position”: { “posX”: “1.26”, “posY”: “3.55”, “at”: “2025-01-13 09:17:18.607”, “numberOfAnchors”: “4”, “clr”: “0.32” }, “slaves”: [ { “address”: “80342827ACA6”, “time”: 0.609190425373519, “fp”: -82.86, “rssi”: -79.13 }, { “address”: “80342827C257”, “time”: 0.609190436174244, “fp”: -89.28, “rssi”: -83.23 }, { “address”: “80342827A461”, “time”: 0.609190439330494, “fp”: -96.61, “rssi”: -87.52 }, { “address”: “803428289F89”, “time”: 0.609190434006911, “fp”: -98.36, “rssi”: -86.72 } ] } } submitted by /u/Spaghettix_ [link] [comments] 

Hi,

sorry if it’s a stupid question, but I never worked with JSON before and I’m struggling with something.

So, I have a UDP communication with sensors sending the data to an IP. The code is this :

import socket import json UDP_IP = "192.168.225.115" UDP_PORT = 5300 max = 10 sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) sock.bind((UDP_IP, UDP_PORT)) print(f"Listening for UDP packets on {UDP_IP}:{UDP_PORT}...") for i in range(0,max): data, addr = sock.recvfrom(2048) parsed_data = json.loads(data) 

And I get this error :

Traceback (most recent call last): File "C:UsersADPFISTEPycharmProjectsSewioAPIUDP sockets saving.py", line 18, in <module> parsed_data = json.loads(data) ^^^^^^^^^^^^^^^^ File "C:Program FilesWindowsAppsPythonSoftwareFoundation.Python.3.12_3.12.2288.0_x64__qbz5n2kfra8p0Libjson__init__.py", line 346, in loads return _default_decoder.decode(s) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:Program FilesWindowsAppsPythonSoftwareFoundation.Python.3.12_3.12.2288.0_x64__qbz5n2kfra8p0Libjsondecoder.py", line 341, in decode raise JSONDecodeError("Extra data", s, end) json.decoder.JSONDecodeError: Extra data: line 1 column 943 (char 942) 

What I don’t understand is that my JSON file is a good format, here is the file :

Any idea why it doesn’t work ?

{ "id": "8", "address": "0x24046650686A", "uuid": "2a886974-b235-11ef-9212-24046650686a", "datastreams": [ { "id": "posX", "current_value": " 1.16", "at": "2025-01-13 09:17:18.607" }, { "id": "posY", "current_value": " 3.59", "at": "2025-01-13 09:17:18.607" }, { "id": "clr", "current_value": " 0.32", "at": "2025-01-13 09:17:18.607" }, { "id": "numberOfAnchors", "current_value": "4", "at": "2025-01-13 09:17:18.607" } ], "extended_tag_position": { "master": "803428289F89", "seq": 5, "calculation": { "at": "2025-01-13 09:17:18.631" }, "corrected": false, "raw_position": { "posX": "1.26", "posY": "3.55", "at": "2025-01-13 09:17:18.607", "numberOfAnchors": "4", "clr": "0.32" }, "slaves": [ { "address": "80342827ACA6", "time": 0.609190425373519, "fp": -82.86, "rssi": -79.13 }, { "address": "80342827C257", "time": 0.609190436174244, "fp": -89.28, "rssi": -83.23 }, { "address": "80342827A461", "time": 0.609190439330494, "fp": -96.61, "rssi": -87.52 }, { "address": "803428289F89", "time": 0.609190434006911, "fp": -98.36, "rssi": -86.72 } ] } } 

submitted by /u/Spaghettix_
[link] [comments] 

Leave a Reply

Your email address will not be published. Required fields are marked *