How to know what is wrong in a JSON object? - json

I am trying to send the following JSON object and I get the error shown below,I checked #http://jsonviewer.stack.hu ,the JSON format seems to be correct,what am I missing and how to fix this?
{"component":{"name":"Company tech (New Bugs)", "version":"B"},"assignee":1234456,"milestone":"chiHW","priority":2,"state":"Analyze","substate":"Nominate","title":"[please ignore]CS\:4355C1\,4364B2\:WDI\:DHD\:HLK\(16299\)\-\>\"DF\ \-\ Sleep\ Tests\"\-\>Assert\-\>bcmpciedhd63\.sys\(dhd\_os\_ioctl\_resp\_wait\)\-\>dhd\_ndis\.c\#4449"}
Error:-
{"message":"An invalid JSON Object was passed in the request body. Please pass a valid JSON object.","help":"View documentation at http://bugs.company.com/","title":"Invalid Request","status":"400 Bad Request"}

You could have pasted your expression into https://jsonlint.com. It tells you where the problem is, and you can experiment until the JSON is no longer invalid. In your case, the problem is those backslashes in the last dictionary value (the one that starts "please ignore").

You could use jq to get a more specific parse error
watson:~$ cat >j
{"component":{"name":"Company tech (New Bugs)", "version":"B"},"assignee":1234456,"milestone":"chiHW","priority":2,"state":"Analyze","substate":"Nominate","title":"[please ignore]CS\:4355C1\,4364B2\:WDI\:DHD\:HLK\(16299\)\-\>\"DF\ \-\ Sleep\ Tests\"\-\>Assert\-\>bcmpciedhd63\.sys\(dhd\_os\_ioctl\_resp\_wait\)\-\>dhd\_ndis\.c\#4449"}
^D
watson:~$ jq <j
parse error: Invalid escape at line 1, column 333

Related

Invalid JSON syntax error in configuration file on homebridge

{
"bridge":{
"name":"Homebridge F8F5",
"username":"0E:8F:12:8D:F8:F5",
"port":51739,
"pin":"670-48-238"
},
"accessories":[
],
"platforms":[
{
"name":"Config",
"port":8581,
"platform":"config"
}
]
}{
"accessories":[
{
"name":"Roku",
"accessory":"Roku",
"ip":"http://10.204.1.238:8060",
}
I am getting an error when I try to run this config file in homebridge. What am I doing wrong? When I try to submit it through the web interface it will not allow me to and says “Config JSON error: invalid json syntax” Any help will be welcome! I have tried to put it through an online json error finder and it narrowed it down to this snippet.
Ummm... looks like you tried to edit this file without knowing the basic concepts of JSON.
Start by reading JSON - Introduction on W2Schools.com
Also, if you're not sure, use an online JSON validator. Use your fav. search engine to look for "JSON cleaner". (I use JSON Formatter & Validator at Curious Concept.)
Off the bat I can see a few issues with the JSON you provided.
the "}{" string ... what's that for? JSON cannot parse that ... either add "," between (if you wanted a new set) or (in this case) remove it.
you have two "accessories". JSON usually get parsed into an object or array ... one cannot have duplicates on the ket names. (In this case) remove the first one.
the second "accessories" array (denoted by "[") has no end (no "]")
the whole set (started with "{") has no end (no "}")

json.loads() fails on my data read from a socket

i got some problems with my code. After i read a JSON received via socket by a Qt client in a python server, i want to get all the fields of that JSON so i can use it, but i got an error like this: json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0). This is the code that cause the exception to raise.
data = connection.recv(1024)
temp = data.decode("utf-8")
jdata = json.loads(temp)
The exception is raised by json.loads(temp). I tried to be sure to have the right type for the loads function, i tried to copy the same string that i get from the socket into another str type and the function works well. Does anyone knows if there is something i overlooked?
update: I just found out that the JSON i get from the socket have a size that differs from a string with the same characters
the exception "json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)" usually indicates that the data you're trying to load is not valid JSON.
See Python JSON Docs
"If the data being deserialized is not a valid JSON document, a JSONDecodeError will be raised." (Scroll down to json.loads function)
Can you print out your temp variable? You'll be able to see the value you're trying to JSONDecode.

Getting error while converting json file to a data frame using jsonlite

I am using the tweetscores package of R to get 'tweets list from twitter. The tweets are stored in json format. While converting it to a data frame I get a lexical error
' Error: lexical error: inside a string, '\' occurs before a character which it may not.".
Any solution to the mentioned error.
A part of the json file text
":[{"text":["MUFC"],"indices":[[83],[88]]}],"symbols":[],"user_mentions":[],"urls":[]},"metadata":{"iso_language_code":["en"],"result_type":["recent"]},"source":["http://twitter.com/download/iphone\" rel=\"nofollow\">Twitter for iPhone</a>"],"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":[7.32108114527322e+017],"id_str":["732108114527322112"],"name":["wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww(^o^)/"],"screen_name":["SukiSukinal"],"location":["+6222"],"description":["Alliansi osaosi ngevote kagak. katanya sih fans a.k.a + "],"url":null,"entities":{"description":{"urls":[]}},"protected":[false],"followers_count":[163],"friends_count":[107],"listed_count":[4],"created_at":["Mon May 16 07:19:11 +0000
Json format does not allow backslashes so you need to escape them. replace any '\' character found with '\\'. Refer [here][1]
[1]: http://www.json.org/ for more info
You likely have an incomplete json string, which may be caused by the package or by an interrupted connection to Twitter's API. A complete json string returned from Twitter should look something like the following:
which I got using rtweet's stream_tweets() function. With a complete string returned by Twitter's REST or stream API, you should be able to convert the data using basically any json parser (e.g., jsonlite::fromJSON()).

JSON Missing ‘}’ or object member name

I was trying to help a friend use JSON commands in Windows 10 Minecraft which uses the JSON format. Well I entered this code below and I got the message
“ * Line 1, Column 2 Missing ‘}’ or object member name “
/give #p stick 1 0 {ench:[{"id":3,"lvl":3}]}
In order to be valid JSON, that object would need double-quotes around the ench key:
{"ench":[{"id":3,"lvl":3}]}
In the future, you can use a tool like jslint to validate JSON.

how to escape special character '?' while inserting into memsql

I am trying to insert JSON payload into memsql JSON type column but it is failing due to the following reason.
My JSON content having '?' character.
I tried to escape '?' by using the following ways, but it doesn't worked for me.
The Exception i am getting is:
Root Exception stack trace:
java.lang.IndexOutOfBoundsException: Index: 0
Ex payload: "question mark content?"
1. #[org.mule.util.StringUtils.replace(payload,"?","\\?")]
Result: "question mark content\?"
2. #[org.mule.util.StringUtils.replace(payload,"?","\?")]
Result: not allowed to use the above expression
If i use the payload "question mark content" then it is inserted successfully.
Please help me how can I escape '?' in my JSON content while saving it into memsql?
'\?' itself is an escape sequence, so achive this you have to use "\\?" which produce "\?" which should work with memsql.
#[org.mule.util.StringUtils.replace(payload,"?","\\\\?")]
Hope this helps.
From the looks of your exception it looks like you are calling for it to replace the payload, but you're not assigning it to anything.
Going off of the documentation at:
http://grepcode.com/file/repo1.maven.org/maven2/commons-lang/commons-lang/2.4/org/apache/commons/lang/StringUtils.java#3457
It basically says that it's trying to replace the items in a string, and the method itself returns a string. Based on what I can tell in the stack trace, it seems as though you are passing a null or uninitialized variable to something that's trying to parse str[0], which is returning an array out of bounds error.
The way to correct this would be to do something like:
payload = org.mule.util.StringUtils.replace(payload,"?","\\\\?")
Which should replace any instance of ? with \? and re-write it to the payload variable. That said, it sounds like payload may actually be null when you're evaluating it later in your program, which could be indicative of a larger issue.