简体   繁体   中英

Getting Syntax Error for Triple nested JSON Object when test in Postman

I am getting a syntax error on line 16 denoting "bad string"

Not sure what is wrong here.

{
    "username": "email",
    "password": "eagle",
    "firstName": "Cameron",
    "lastName": "Elliott",
    "phoneNumber": 1112223333,
    "photo": "What ever a photo looks like",
    "aboutMe": "Hi my name is Cameron Elliott, Your new surfing instructor!",
    "availability": {
        "monday": {
            "available": true,
            "day": "Monday",
            "startTime": [0900, 1400],
            "endTime": [1230, 1700],
            "beaches": ["Ocean Beach", "South Mission Beach", "Mission Beach", "Pacific Beach", "Tourmoline", "La Jolla Shores"],
        },
        "tuesday": {
            "available": true,
            "day": "Tuesday",
            "startTime": [0900, 1400],
            "endTime": [1230, 1700],
            "beaches": ["Ocean Beach", "South Mission Beach", "Mission Beach", "Pacific Beach", "Tourmoline", "La Jolla Shores"],
        },
        "wednesday": {
            "available": true,
            "day": "Wednesday",
            "startTime": [0900, 1400],
            "endTime": [1230, 1700],
            "beaches": ["Ocean Beach", "South Mission Beach", "Mission Beach", "Pacific Beach", "Tourmoline", "La Jolla Shores"],
        },
        "thursday": {
            "available": true,
            "day": "Thursday",
            "startTime": [0900, 1400],
            "endTime": [1230, 1700],
            "beaches": ["Ocean Beach", "South Mission Beach", "Mission Beach", "Pacific Beach", "Tourmoline", "La Jolla Shores"],
        },
        "friday": {
            "available": true,
            "day": "Friday",
            "startTime": [0900, 1400],
            "endTime": [1230, 1700],
            "beaches": ["Ocean Beach", "South Mission Beach", "Mission Beach", "Pacific Beach", "Tourmoline", "La Jolla Shores"],
        },
        "saturday": {
            "available": true,
            "day": "Saturday",
            "startTime": [0900, 1400],
            "endTime": [1230, 1700],
            "beaches": ["Ocean Beach", "South Mission Beach", "Mission Beach", "Pacific Beach", "Tourmoline", "La Jolla Shores"],
        },
        "sunday": {
            "available": true,
            "day": "Sunday",
            "startTime": [0900, 1400],
            "endTime": [1230, 1700],
            "beaches": ["Ocean Beach", "South Mission Beach", "Mission Beach", "Pacific Beach", "Tourmoline", "La Jolla Shores"],
        },
    },
}

I would love to know what I'm doing wrong here. just stepping into setting up database schema and models so any info on whats wrong is awesome.

For example, maybe using an array very an object or using different types of structuring.

At the first look, the JSON given to the question looks good. However, there are few issues. To understand it, let's remove some data and make it simple. So, here is the simple JSON that has issues.

{
    "username": "email",
    "password": "eagle",
    "firstName": "Cameron",
    "lastName": "Elliott",
    "phoneNumber": 1112223333,
    "photo": "What ever a photo looks like",
    "aboutMe": "Hi my name is Cameron Elliott, Your new surfing instructor!",
    "availability": {
        "monday": {
            "available": true,
            "day": "Monday",
            "startTime": [0900, 1400],
            "endTime": [1230, 1700],
            "beaches": ["Ocean Beach", "South Mission Beach", "Mission Beach", "Pacific Beach", "Tourmoline", "La Jolla Shores"],
        }
    },
}

Issue 1:
In JavaScript, if a number starts with a 0 that isn't immediately followed by a . , it represents an octal, not a decimal number. Thus you need to change the value of startTime and endTime . you can make it string or change the value. Here I'm changing it as string type

"startTime": ["0900", "1400"],
"endTime": ["1230", "1700"],

Issue 2:
Remove comma at closing bracket of beaches

Error: Parse error on line 15:
...a Jolla Shores"],        }   },}
----------------------^
Expecting 'STRING', got '}'

Issue 3:
Remove comma at closing bracket of availability

在此处输入图片说明

Final valid JSON

{
    "username": "email",
    "password": "eagle",
    "firstName": "Cameron",
    "lastName": "Elliott",
    "phoneNumber": 1112223333,
    "photo": "What ever a photo looks like",
    "aboutMe": "Hi my name is Cameron Elliott, Your new surfing instructor!",
    "availability": {
        "monday": {
            "available": true,
            "day": "Monday",
            "startTime": ["0900", "1400"],
            "endTime": ["1230", "1700"],
            "beaches": ["Ocean Beach", "South Mission Beach", "Mission Beach", "Pacific Beach", "Tourmoline", "La Jolla Shores"]
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM