{"meta":{"title":"Debugging invalid JSON","intro":"Copilot Chat can identify and resolve syntax errors or structural issues in JSON data.","product":"GitHub Copilot","breadcrumbs":[{"href":"/en/copilot","title":"GitHub Copilot"},{"href":"/en/copilot/tutorials","title":"Tutorials"},{"href":"/en/copilot/tutorials/copilot-chat-cookbook","title":"GitHub Copilot Chat Cookbook"},{"href":"/en/copilot/tutorials/copilot-chat-cookbook/debug-errors","title":"Debug errors"},{"href":"/en/copilot/tutorials/copilot-chat-cookbook/debug-errors/debug-invalid-json","title":"Debug invalid JSON"}],"documentType":"article"},"body":"# Debugging invalid JSON\n\nCopilot Chat can identify and resolve syntax errors or structural issues in JSON data.\n\nWhen working with JSON data, you may encounter issues such as trailing commas, mismatched braces, or incorrect data types that make the JSON invalid. GitHub Copilot Chat can help you debug and fix these errors by suggesting corrections to fix invalid JSON.\n\n## Example scenario\n\nConsider a scenario where an application consumes JSON data from an API, but the response fails to parse due to invalid formatting. You receive the error message:\n\n```bash\nError: Parse error\n----------------------^\nExpecting 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '[', got 'undefined'\n```\n\nBelow is the JSON data that caused the error:\n\n```json id=json-error\n{\n  \"location\": \"San Francisco\",\n  \"current_weather\": {\n    \"temperature\": 18,\n    \"unit\": \"Celsius\",\n    \"conditions\": \"Cloudy\n  },\n  \"forecast\": {\n    \"day\": \"Monday\",\n    \"high\": 22,\n    \"low\": 15,\n    \"precipitation\": 10\n  }\n}\n```\n\n## Example prompt\n\n```copilot copy prompt ref=json-error\nWhy is my JSON object invalid and how can I fix it?\n```\n\n## Example response\n\n> \\[!NOTE] The following response is an example. Copilot Chat responses are non-deterministic, so you may get a different response from the one shown here.\n\nCopilot might suggest that your JSON is invalid because it's missing a closing quote for the `conditions` value. Here is the corrected JSON:\n\n```json\n{\n  \"location\": \"San Francisco\",\n  \"current_weather\": {\n    \"temperature\": 18,\n    \"unit\": \"Celsius\",\n    \"conditions\": \"Cloudy\"\n  },\n  \"forecast\": {\n    \"day\": \"Monday\",\n    \"high\": 22,\n    \"low\": 15,\n    \"precipitation\": 10\n  }\n}\n```\n\nIn this example response, Copilot's suggestions include fixing the closing quote for the `conditions` value, which resolves the JSON parsing error.\n\n## Further reading\n\n* [Prompt engineering for GitHub Copilot Chat](/en/copilot/using-github-copilot/prompt-engineering-for-github-copilot)\n* [Best practices for using GitHub Copilot](/en/copilot/using-github-copilot/best-practices-for-using-github-copilot)"}