Skip to content
the poor coder

JSON won't compile. gives: "Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE'

Poor Man
Published
Reading time
2 min read
On this page

JSON Won't Compile: "Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE'"#

If you are encountering the error message "Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE'" while trying to compile your JSON, it means that there is a syntax error in your code that is preventing it from being parsed correctly. This error message is a common one that developers encounter when working with JSON, and it can be frustrating to troubleshoot.

What is JSON?#

JSON, or JavaScript Object Notation, is a lightweight data interchange format that is easy for humans to read and write, and easy for machines to parse and generate. JSON is often used to transmit data between a server and a web application, and it has become a popular alternative to XML.

Common Causes of the "Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE'" Error#

There are several common reasons why you might encounter this error message while working with JSON:

  • Missing or incorrect syntax: JSON uses a specific syntax that must be followed precisely in order to be parsed correctly. If your JSON code contains missing or incorrect syntax, it can trigger this error message.
  • Unexpected characters: If your JSON code contains unexpected characters, such as extra commas or brackets, it can also trigger this error message.
  • Invalid data types: JSON only allows certain data types to be used, such as strings, numbers, and booleans. If your JSON code contains invalid data types, such as functions or undefined values, it can trigger this error message.

Troubleshooting the Error#

If you are encountering the "Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE'" error message while working with JSON, there are several steps you can take to troubleshoot the issue:

  1. Check your syntax: Make sure that your JSON code follows the correct syntax, including the use of brackets, commas, and quotes.
  2. Validate your JSON: Use a JSON validator tool, such as JSONLint or JSON Checker, to check your code for syntax errors and invalid data types.
  3. Look for unexpected characters: Check your JSON code for unexpected characters, such as extra commas or brackets, that might be causing the error.
  4. Check for encoding issues: Make sure that your JSON code is encoded correctly, as encoding issues can also trigger this error message.

Example Code#

Text

{
  "name": "Raju",
  "age": 25,
  "isAdmin": true,
  "address": {
    "street": "123 Main St",
    "city": "Anytown",
    "state": "CA",
    "zip": "12345"
  },
  "phoneNumbers": [
    {
      "type": "home",
      "number": "555-555-1234"
    },
    {
      "type": "work",
      "number": "555-555-5678"
    }
  ]
}

In the example code above, we have a JSON object that contains information about a person named Raju. The code is properly formatted and contains only valid data types, so it should parse correctly without triggering the "Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE'" error message.

If you are still encountering issues with your JSON code, you may need to seek additional help from a developer or online community. With some careful troubleshooting and attention to detail, however, you should be able to get your JSON code working correctly and eliminate the "Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE'" error message.

Keep going

2023

how to sort an array

How to Sort an Array If you have an array and you want to order its elements in a specific way, you need to use a sorting algorithm. There are several sorting algorithms available, but two of the most commonly used are…

javascript2 min read
2023

jquery mobile or desktop

jQuery Mobile or Desktop? As a web developer, I have had some experience with both jQuery Mobile and jQuery Desktop. Both frameworks have their pros and cons, and which one to use really depends on the specific project…

javascript1 min read
2023

node.js folder structure

Node.js Folder Structure If you are new to Node.js, it can be daunting to create a folder structure that will work for your project. The structure you choose will depend on the size and complexity of your project. Here…

javascript1 min read
ESC