I was trying to format my json in jsonformatter.org and I'm not sure why I'm getting the below error
Parse error on line 1:
...","topBrand":false}{"_id":{"$oid":"601c
----------------------^
Expecting 'EOF', '}', ',', ']', got '{'
[error][1]
Sample JSON:
{"_id":{"$oid":"601ac115be37ce2ead437551"},"barcode":"511111019862","category":"Baking","categoryCode":"BAKING","cpg":{"$id":{"$oid":"601ac114be37ce2ead437550"},"$ref":"Cogs"},"name":"test brand #1612366101024","topBrand":false}
{"_id":{"$oid":"601c5460be37ce2ead43755f"},"barcode":"511111519928","brandCode":"BUCKS","category":"Beverages","categoryCode":"BEVERAGES","cpg":{"$id":{"$oid":"5332f5fbe4b03c9a25efd0ba"},"$ref":"Cogs"},"name":"Starbucks","topBrand":false}
The JSON you posted contains two separate JSON documents, and is thus invalid. That's what the error is complaining about, it expected EOF (i.e. End of File), but it instead got the opening-brace from the second JSON document.
Either format them one at a time, or merge them into one document somehow.
For example, you could turn it into a list:
{
"data": [
{ ... },
{ ... }
]
}
Or a larger compound object:
{
"data1": { ... },
"data2": { ... }
}
Related
Error: Parse error on line 1:
{"Index":{"_id":1}}
{ "altitde": 11887.1,
"callsign": "ABX2040 ",
----------------------^
Expecting 'EOF', '}', ',', ']', got '{'
This piece of text: {"Index":{"_id":1}} is a complete JSON object. After the last "}" your parser is expecting the end of the file, but you are adding a new object, starting with a new "{"
Check http://www.json.org/ to see how correct JSON must be conformed
I'm new to bash script, i want to make automation to delete the old saved record in elasticsearch. I can Perform this action by manually using curl command,
" curl -XDELETE 'index name/_query' -d '
{
"query":
{
"range":
{
"eventType_timestamp":
{
"gte": "2016-05-30T07:00:00.000Z",
"lte": "2016-06-15T06:59:59.999Z"
}
}
}
}'
Instead of passing the date manually, I want to parse the date automatically by shell script. I retrieved the date and stored in a fields when I pass those fields into script I am getting some error
" curl -XDELETE 'index name/_query' -d '
{
"query":
{
"range":
{
"eventType_timestamp":
{
"gte": $from_dataset_date,
"lte": $to_dataset_date
}
}
}
}'"
Error: This is error I am getting while run the above curl
{"error":{"root_cause":[{"type":"jsonparse_exception","reason":"jsonparse_exception: Unrecognized token '$fromdatasetdate': was expecting ('true', 'false' or 'null')\n at [Source: [B#ba52ee7; line: 9, column: 33]"}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"","node":"-oHm1uxQQ6e7RTnCaWtQEw","reason":{"type":"query_parsing_exception","reason":"Failed to parse","index":"-dd.","caused_by":{"type":"json_parse_exception","reason":"json_parse_exception: Unrecognized token '$from_dataset_date': was expecting ('true', 'false' or 'null')\n at [Source: [B#ba52ee7; line: 9, column: 33]"}}}]},"status":400}
Seems it is a problem with quoting - combination with single quote, double quote and escaping . Curl send json data. Bash variable should be in double quotes but json data should start with single quote.
Example:
data="'"'{"json": "finish string after single quote ->", '"\"$BASH_VAR\""',"json1": "finish data"}'"'"
In above example I used concatenate strings in single quote and double quote ("'"'{..' for ' add to {.. ).
Try something like this in bash script
curl -XDELETE 'index name/_query' -d "'"'
{
"query":
{
"range":
{
"eventType_timestamp":
{
"gte": '"\"$from_dataset_date\""',
"lte": $to_dataset_date
}
}
}
}'"'"
I try to find out why my JSON is not legal.
I use this site: http://jsonlint.com/
The first example which is good is:
{
"data": 1290,
"value": "a"
}
The second which is not good is:
{
"data": 1290,
"value": "a"
}
I dont understand why the second one does not work. Its the same as the first one.
EDIT
I found this sings at the end of the string.
How to remove them using PHP? the string source is from php.
There might be some additional output after you output your json. Try trimming output and terminating further execution.
$json = array('data' => 1290, 'value' => 'a');
echo json_encode($json);
die();
This is the json .
"{
'places': [
{
'name': 'New\x20Orleans,
\x20US\x20\x28New\x20Lakefront\x20\x2D\x20NEW\x29',
'code': 'NEW'
}
]
}"
I am getting json parsererror. I am checking on http://jsonlint.com/ and it shows following error
Parse error on line 1:
"{ 'places': [
^
Expecting '{', '['
Please explain what are the problems with the json and do I correct it?
If you literally mean that the string, as a whole, is your JSON text (containing something that isn't JSON), there are three issues:
It's just a JSON fragment, not a full JSON document.
Literal line breaks within strings are not valid in JSON, use \n.
\x is an invalid escape sequence in JSON strings. If you want your contained non-JSON text to have a \x escape (e.g., when you read the value of the overall string and parse it), you have to escape that backslash: \\x.
In a full JSON document, the top level must be an object or array:
{"prop": "value"}
[1, 2, 3]
Most JSON parsers support parsing fragments, such as standalone strings. (For instance, JavaScript's JSON.parse supports this.) http://jsonlint.com is doing full document parsing, however.
Here's your fragment wrapped in an object with the line breaks and \x issue handled:
{
"stuff": "{\n 'places': [\n {\n 'name': 'New\\x20Orleans,\n \\x20US\\x20\\x28New\\x20Lakefront\\x20\\x2D\\x20NEW\\x29',\n 'code': 'NEW'\n }\n \n ]\n }"
}
The text within the string is also not valid JSON, but perhaps it's not meant to be. For completeness: JSON requires that all keys and strings be in double quotes ("), not single quotes ('). It also doesn't allow literal line breaks within string literals (use \n instead), and doesn't support \x escapes. See http://json.org for details.
Here's a version as valid JSON with the \x converted to the correct JSON \u escape:
{
"places": [
{
"name": "New\u0020Orleans,\n\u0020US\u0020\u0028New\u0020Lakefront\u0020\u002D\u0020NEW\u0029",
"code": "NEW"
}
]
}
...also those escapes are all actually defining perfectly normal characters, so:
{
"places": [
{
"name": "New Orleans,\n US (New Lakefront - NEW)",
"code": "NEW"
}
]
}
read http://json.org/
{
"places": [
{
"name": "New\\x20Orleans,\\x20US\\x20\\x28New\\x20Lakefront\\x20\\x2D\\x20NEW\\x29",
"code": "NEW"
}
]
}
I have JSON file with up to 1,500 items. Apparently, there is an error.
I have taken the first and last fields and tried to validate it. I have copied and pasted the below code, but I'm getting errors.
[{
"username" : "testuser0",
"date_added" : "04/07/13",
"description" : "Desc"
},
{
"username" : "testuser1",
"date_added" : "04/07/13",
"description" : "Desc"
}];
And this is what it says, even though I don't think there's anything wrong with it:
Parse error on line 12: ...ion": "Desc" }];
---------------------^ Expecting 'EOF', '}', ',', ']'
Remove the trailing semi-colon ;
It shouldn't be there for JSON (it is not javascript)