JSON format with index error - json

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

Related

JSON says Expecting 'EOF', '}', ',', ']', got '{'

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": { ... }
}

Expecting 'EOF' error when importing a json file in MongoDB

I am trying to import the following json file into MongoDB with Compass but I get an error:
Unexpected token � in JSON at position 0 while parsing near '�' in C:\Users\antoi\Downloads\restaurants.json
> 1 | �
| ^
Then I tried to test it from another source but it didn't work:
Error: Parse error on line 10:
...s Park Bake Shop"} { "_id": { "$oid"
----------------------^
Expecting 'EOF', '}', ',', ']', got '{'
is a quotation mark missing? But when I add a quotation mark it gives me:
Error: Parse error on line 10:
...is Park Bake Shop"}, { "_id": { "$oi
----------------------^
Expecting 'EOF', got ','
Use mongoimport
mongoimport --db myDb --collection restaurants --file restaurants.json
restaurants.json is not a valid JSON, not wrapped in array nor it has commas at the end.
https://docs.mongodb.com/manual/reference/mongodb-extended-json/

Ruby Read file without escaping the characters

File Content:
file.txt:
{ 'a' : 'b"c\g' }
Need to parse this JSON.
read_file = File.read(file.txt)
This read_file string is of the form : "{ 'a' : 'b\"c\\g'}\n".
While parsing the JSON:
JSON::ParserError: 757: unexpected token at '{ 'a' : 'b"c\g'}
from /usr/share/ruby/json/common.rb:155:in `parse'
from /usr/share/ruby/json/common.rb:155:in `parse'
from (irb):21
from /usr/bin/irb:12:in `<main>`
The file could contain any escaping sequence or wild-cards, but it will always be in JSON format.
How to parse such JSON file to ruby Hash?
This is because the json in your text file is invalid. Here is a similar question about parsing a json string using single quotes. For this to be valid json it needs
Double quotes
Escaped special characters
Without this you'll be unable to parse it as it won't be recognized as valid json. Try parsing this text instead:
{ "a": "b\"c\\g" } => {"a"=>"b\"c\g"}

Parse json with newline

Given a Json like this:
{
"description": "foo \n bar"
}
If I try to create a Hash(String, String) using method from_json I get the following error:
Unexpected char '
' at 1:22 (JSON::ParseException)
How can I correctly parse it?
require "json"
Hash(String, String).from_json(%({"description": "foo \n bar"}))
https://play.crystal-lang.org/#/r/3ynh

Postgres 9.4 JSON: Handle with double quotes inside value

I have a json data with double quotes inside value.
For example, '{"resource": "xml version=\"1.0\" "}',
and when I run any json_function I get an error:
select '{"resource": "xml version=\"1.0\" "}'::jsonb - 'resource';
ERROR: invalid input syntax for type json Detail: Expected "," or "}", but found "1.0"
Can somebody explain me, please, how to handle these double quotes at this situation?