{
"jsonStringData": " ["Coil",{"CHARGE_ID":"T862270","PROD_ID":"S878412","COMBINE_SPLIT_IND":"S",
"WEIGHT":"234244","FEET":"3535","ORDER_NUMBER":"LI91004","OIL_DRY_IND":"D",
"NEXT_FACILITY":"WHSE", "DEFECT_CODE":"","TEST_CUT_IND":"","NSTD_FAC_REASON_CODE":"",
"COMMENTS":"","SCRAP_FEET":""}]"
}
When I parsed above JSONString using "http://jsonlint.com/", it gives me below error message. I am not sure what that error mean.
Please help me to get the right JSONString.
Error :
Parse error on line 2:
...sonStringData": " ["Coil",{"CHARGE_ID":"
-----------------------^
Expecting '}', ':', ',', ']'
Remove the " after the : and also the closing one at the end.
{
"jsonStringData": [
"Coil",
{
"CHARGE_ID": "T862270",
"PROD_ID": "S878412",
"COMBINE_SPLIT_IND": "S",
"WEIGHT": "234244",
"FEET": "3535",
"ORDER_NUMBER": "LI91004",
"OIL_DRY_IND": "D",
"NEXT_FACILITY": "WHSE",
"DEFECT_CODE": "",
"TEST_CUT_IND": "",
"NSTD_FAC_REASON_CODE": "",
"COMMENTS": "",
"SCRAP_FEET": ""
}
]
}
The quote just before Coil ends the string which was a value. Just after this string you should have either } or , :
(from json.org)
But it looks like the error was to put a json encoded array into quotes when building the complete object.
You should probably have
"jsonStringData": ["C...
instead of
"jsonStringData": " ["C...
Related
I've created a JSON.
This JSON file will be a source of query in ElasticSearch
This query works in ElasticSearch and returns results.
When I store the query to JSON, I see that JSON is valid. But when I read it from JSON I have an error.
It's my JSON:
{
"function_score": {
"query": {
"bool": {
"should": [
{
"query_string": {
"default_field": "headline",
"query": "engineer"
}
},
{
"match_all": {}
}
]
}
},
"functions": [
{
"script_score": {
"script": {
"params": {
"queryVector": [1,2,5],
"max_score": "max_score"
},
"source": "if (_score>0 && params.max_score>0){return doc['embedding_headline'].size() == 0 ? 0 : Math.min(Math.max(_score/params.max_score,cosineSimilarity(params.queryVector, 'embedding_headline')),1) + 1.0} else { return doc['embedding_headline'].size() == 0 ? 0 : cosineSimilarity(params.queryVector, 'embedding_headline') + 1.0}",
"lang": "painless"
}
}
}
],
"score_mode": "max",
"boost_mode": "replace",
}
}
I use python for reading JSON.
It's code for reading:
import json
file_path = 'queries.json'
with open(file_path) as f:
data = json.load(f)
print(data)
It's error:
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 34 column 5 (char 1012)
What should I change in this JSON to make it readable?
Thanks
That json is invalid.
I just pasted it into a json validator and it has errors in it.
CHeck this link:
json lint
Paste your json there, it throws the following errors:
Error: Parse error on line 30:
..._mode": "replace", }}
----------------------^
Expecting 'STRING', got '}'
If you are using python it often throws errors due to string quotation as well.
Try to enclose the script source field in single quotes instead of doubles. That could be another problem.
Last but not the least, function score queries are extremely slow, and I would recommend not using them!
I am working with a MySQL db that has encoded polygon for google maps. When I try to return the query as json, jsonlint complains.. I am not sure why its complaining , I did try escaping the "}" in the latlon but still get the same error.
Parse error on line 20:
... "latlon": "}ciuF|a|pNcUr#d#es#
-----------------------^
Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '['
My json is:
{
"maps": [
{
"group_id": "0",
"user_id": "113",
"group_name": "",
"note": "",
"field_id": "",
"field_name": "West Pasture",
"field_notes": "",
"date_created": "12/31/2012",
"acres": ""
}
],
"polygon": [
{
"polygon_id": "",
"field_id": "1",
"acres": "92",
"latlon": "}ciuF|a|pNcUr#d#es#fIHXaNtCn#UxCjMlApAfFuBpI}E\ChJdEl#xAtE"
}
]
}
The problem is that there is a slash before the C which is not a valid escape sequence.
"}ciuF|a|pNcUr#d#es#fIHXaNtCn#UxCjMlApAfFuBpI}E\ChJdEl#xAtE"
JSON.parse('"\\C"');
This will give you a syntax error because it is trying to parse the string \C. If you want a literal \ in your property's value, you need to escape it.
"latlon": "}ciuF|a|pNcUr#d#es#fIHXaNtCn#UxCjMlApAfFuBpI}E\\ChJdEl#xAtE"
The relevant section from the official grammar:
string
""
" chars "
chars
char
char chars
char
any-Unicode-character-
except-"-or-\-or-
control-character
\"
\\
\/
\b
\f
\n
\r
\t
\u four-hex-digits
I tried to view my JSON file as a tree and I got an error that I don't know how to solve.
error:
Parse error on line 1: ...2","Likes":"0/0"}} {"Id":2,"commContent ----------------------^ Expecting 'EOF', '}', ',', ']', got '{'
JSON output:{"Id":1,"commContent":{"Name":"username1","Comment":"text1","Date":"5.5.2021 10:22","Likes":"0/0"}} {"Id":2,"commContent":{"Name":"username2","Comment":"text2","Date":"5.5.2021 10:24","Likes":"0/0"}}
Json online editor Iam using: https://jsoneditoronline.org/#
There is a problem with the JSON you have produced. You have two distinct elements in the JSON but they are not in an array, so the tree looks like this:
Root element
Root element
The error messages is correctly identifying the problem - it is expecting EOF but instead is receiving a new element starting with {.
That doesn't make any sense - the elements probably need to be nested in an array (surrounded with [] and with a comma , between), like this:
[
{
"Id": 1,
"commContent": {
"Name": "username1",
"Comment": "text1",
"Date": "5.5.2021 10:22",
"Likes": "0/0"
}
},
{
"Id": 2,
"commContent": {
"Name": "username2",
"Comment": "text2",
"Date": "5.5.2021 10:24",
"Likes": "0/0"
}
}
]
The above would be considered valid.
The Newline delimited JSON file parsing correctly for below JSON Structure.
{
"name": "Honeywell",
"BOM": "12 GENUINE MIX RESISTOR KIT 150PCS 30\n1/21/4W + MIX zelatin CAPACITOR KIT\n3",
"url": "http://fairchild.com",
"image": "http://fairchild.com/over.jpg",
"ThresholdRange": "2M",
"Peak": "8",
"date": "2003-04-01",
"DeadTime": "15M"
},
But As soon i am adding below line it is throwing Error.
{
"name": "VishayElectronics.com",
"BOM": "12 GENUINE MIX RESISTOR KIT 150PCS 30\n1/21/4W + MIX power CAPACITOR KIT\n3",
"url": "http://vishay.com",
"image": "http://vishay/to.jpg",
"ThresholdRange": "10M",
"Peak": "8",
"date": "2011-06-06",
"DeadTime": "6M"
}
i am validating using https://jsonlint.com/
Error: Parse error on line 10:
...adTime": "15M"}{ "name": "VishayEl
--------------------^
Expecting 'EOF', '}', ',', ']', got '{'
May someone please help me what changes i should make to resolve error.
Many Thanks.
You lost a "," between your first object and the second one.
I want to decode in extjs4 with Ext.decode(string), a json string with json string inside, just like this:
var string = "{success:true,
rows:[{"jsonfields":"[
{\\"name\\":\\"cm:title\\",\\"title\\":\\"Titolo\\",\\"description\\":\\"Titolo del contenuto\\",\\"dataType\\":\\"d:mltext\\",\\"url\\":\\"\/api\/property\/cm_title\\"},
{\\"name\\":\\"cm:content\\",\\"title\\":\\"Contenuto\\",\\"description\\":\\"Contenuto\\",\\"dataType\\":\\"d:content\\",\\"url\\":\\"\/api\/property\/cm_content\\"},
{\\"name\\":\\"cm:name\\",\\"title\\":\\"Nome\\",\\"description\\":\\"Nome\\",\\"dataType\\":\\"d:text\\",\\"url\\":\\"\/api\/property\/cm_name\\"}]"}
]}";
As you can see "jsonfields" is a json string code.
How I can decode this string with Ext.decode(string)
Any suggests?
There were a couple of problems with your JSON code.
All of your keys needed to be in quotes (success and rows were not).
Use single quotes when embedding a JSON string directly into javascript. This way you can avoid using the escape character.
Below is the correct JSON code. I have also updated your jsfiddle link.
var string = '{
"success": true,
"rows": [
{
"jsonfields": [
{
"name": "cm: title",
"title": "Titolo",
"description": "Titolodelcontenuto",
"dataType": "d: mltext",
"url": "/api/property/cm_title"
},
{
"name": "cm: content",
"title": "Contenuto",
"description": "Contenuto",
"dataType": "d: content",
"url": "/api/property/cm_content"
},
{
"name": "cm: name",
"title": "Nome",
"description": "Nome",
"dataType": "d: text",
"url": "/api/property/cm_name"
}
]
}
]}';
var decodedString = Ext.decode(string);
console.log(decodedString);
That's the correct way to decode JSON with Ext and the exception is likely telling you about some invalid syntax in your JSON string. The JSON format is very strict.
You can use an online validator like jsonlint to help figure out what's wrong with your syntax.
One other note: in cases like this, it's usually easier to use single quotes around your string so that you can embed double-quotes without having to escape them.
var string = '{ "success": true, ...}'