I am having this json but Visual Studio Code gives me the warning in the title.
[
{
"title": "Book A",
"imageUrl": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ6B1bizZf6gt_7vtUZXx0cPf81u07iJf9ZPBMPn5kM_5pyIRnE",
"description": "Cool book!",
"price": "10",
"id": "0.9910457947149673"
},
{
"title": "Book B",
"imageUrl": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ6B1bizZf6gt_7vtUZXx0cPf81u07iJf9ZPBMPn5kM_5pyIRnE",
"description": "Nice!",
"price": "12",
"id": "0.3677736742556723"
},
{
"id": "0.2599869075653567",
"title": "Αχίλλιου Πόλης",
"imageUrl": "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBxMSERUTEhIWFhUXGRgZGBgWGBgYHRYZGBsaGB4YGxkYHSggGBolIBgXITEhJSkrLi4uGB8zODMtNygtLisBCgoKDg0OGBAQGi0dHh8rKy0tLSsrLS0tLSsrKy0tKy0rLS0tLS0tLS0tLS0tLS0tLS03LS0tLTcrLTc3NzcrLf/AABEIAOEA4AMBIgACEQEDEQH/xAAcAAACAgMBAQAAAAAAAAAAAAAABQQGAgMHAQj/xABGEAABAwEGBAMEBggFAgcBAAABAAIRAwQFEiExQQZRYXETIpEygbHBBxRCUqHwIzM0YnJz0eEVJILC8RayNURTVIOSoiX/xAAYAQEBAQEBAAAAAAAAAAAAAAAAAQIDBP/EACERAQEAAgIDAAMBAQAAAAAAAAABAhESIQMxQSJRkTIT/9oADAMBAAIRAxEAPwC/IQhUCEIQCELCvWaxpe8hrWiSTsEGaFjTeHAOaZBEgjcHdZIBCEIBCEIBCEIBCEIBCEIBCEIBCEIBCEIBCEIBCEIBKbzv+lQfgdLjEnDEN7k79Ej4r4mdTqOoU3YSMIJGpxbA7Kr2yyP8NgY5jsbnE43VJAxHzZHTJB0SzcR0H6OcO7T8VNpXhSdo9use/wB65lcdpfSfUpOmWhj83NIe06Fpw/hOyd0ra7EQ9hJfu1khw2g4vL26oL2qjx1UqVm/VKAlxaalToxuje52Vmr120qRe4w1jZPQAJHwq9pa+01XsFSucRBc2WsGTW68vis39OuHV5If0bXv4tnNFx81LIdWHT00VwXK7RUF3XnjY4Gk8ycJBAY45j3HNdTa4ESDkcx2KY34vmx1dz6UXxxHRspiqKgGzgwlp6A81sua/aVqzpB5bn5i0gZbTzUy8LEyvTdSqNlrhB/r3XNLJba10Wh9J4L6TgSP3vuuB2OxUtsMMMc5qe11tvFdClU8J7aofsPDJxdRGoUm237TpUxUf",
"description": "A cool book. Everyone should buy it!",
"price": "10"
},
{
"id": "0.8862598606325078",
"title": "xvbxb",
"imageUrl": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ6B1bizZf6gt_7vtUZXx0cPf81u07iJf9ZPBMPn5kM_5pyIRnE",
"description": "xvcxv",
"price": "20"
}
]
Why?
The top level JSON is historically expected be an object. Not an array or primitive.
In practice the enforcement of that rule varies. VSCode is reminding you that you're not looking at JSON in the most interoperable sense.
Edit: There are various RFCs which define JSON, the historical ones are usually stricter, but have nowdays been mostly superseded.
I am at a loss as to finding an official JSON definition that enforces the 'top level item is an object' rule. I suspect it's just been the reality with regards to browser support, and other parsers for a while, so it became a de-facto standard, before being properly standardized.
See for example: rfc4627 rfc7159 rfc8259
I'm having the same problem, and it turns out it's caused by an extension instead of VSCode itself.
Click on the icon of Editor Language Status, and then click Show Schemas to check if there is any JSON schema configured. Try to change the schema or disable related extension to see if it solves the problem.
In my case, it's caused by a JSON schema configured by extension.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With