JSON Practice: Fix an Invalid API Response
JavaScript object literals and JSON look similar, but they follow different rules. JSON is a data format used by many APIs. This exercise repairs the syntax of a document without changing what the data means.
Before you start: Objects, arrays, strings and boolean values.
Your task
Replace single quotes with double quotes, quote property names and remove the trailing comma so the document is valid JSON.
Starter code
{
name: 'Sukoaa',
"tools": ["Python", "JavaScript",],
"active": true
}
Expected result
Valid JSON with name, tools and active properties.Loads the starter in the workspace. Save or export existing work first. Return here for hints and the explanation.
Need a hint?
Look for an unquoted key, a single-quoted string and a comma immediately before a closing bracket.
Show the complete solution and walkthrough
{
"name": "Sukoaa",
"tools": ["Python", "JavaScript"],
"active": true
}
- Quote the name property with double quotes. JSON object member names must be strings written with double quotes.
- Change the Sukoaa string to double quotes. Keep true as a boolean without quotation marks.
- Remove the comma after JavaScript in the tools array. Keep the commas that separate members. Validate the complete document again after every repair.
A common mistake
Replacing every quote blindly can damage embedded quotation marks. JSON also does not accept comments or JavaScript values such as undefined.
Try an edge case
A document can be syntactically valid yet have the wrong shape for your API. JSON validation alone does not check that name is a string or tools contains supported names.
Take it one step further
Add a version number and an empty notes array. Then try an escaped quotation mark inside a string and validate the document.