You are trying to map clubs to two separate arrays (each containing a single object), rather than a single array with two objects.

json_clubs = {
    "clubs": [
        {
            "Oak Club": {
                    "members": [
                        "Charles",
                        "Nora",
                        "Tom",
                        "Paul"
                        ]
                    }
        },
        {
            "Bravo Club": {
                "members": [
                    "Nathaniel",
                    "Roselyn",
                    "Ash"
                    ]
                }
        }
    ]
}
Answer from chepner on Stack Overflow
🌐
JSONLint
jsonlint.com › json-syntax-error
JSON Syntax Error: How to Find and Fix It | JSONLint
Unlike some formats that are forgiving, JSON requires exact syntax—a single misplaced character will cause the entire document to fail parsing. This guide will help you quickly identify what's wrong and fix it. The fastest way to find a syntax error is to paste your JSON into the JSON Validator.
🌐
Bubble
forum.bubble.io › need help
JSON Syntax Error - Need help - Bubble Forum
February 23, 2024 - Hello, I’m trying to create a JSON and send it via an API to XANO, but keep receiving the error message: “Error parsing JSON: Syntax error”} After trying a lot of different things, I found a way to “fix” the problem. I added the JSON to a Custom State, which populates an Input.
🌐
DZone
dzone.com › coding › languages › syntaxerror: json.parse: bad parsing
SyntaxError: JSON.parse: bad parsing
February 25, 2019 - And some of them are very tricky ... object of the main error object The main reason behind the error is usually a mistake in the JSON file syntax....
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Errors › JSON_bad_parse
SyntaxError: JSON.parse: bad parsing - JavaScript | MDN
SyntaxError · JSON.parse() parses a string as JSON. This string has to be valid JSON and will throw this error if incorrect syntax was encountered. Both lines will throw a SyntaxError: js · JSON.parse("[1, 2, 3, 4,]"); JSON.parse('{"foo": 1,}'); // SyntaxError JSON.parse: unexpected character // at line 1 column 14 of the JSON data ·
🌐
Bobby Hadz
bobbyhadz.com › blog › javascript-syntaxerror-json-parse-unexpected-character
SyntaxError: JSON.parse unexpected character in JavaScript | bobbyhadz
The "SyntaxError JSON.parse unexpected character at line" error occurs when we try to `JSON.parse` a value that is not a valid JSON string.
Find elsewhere
Top answer
1 of 16
62

For the benefit of searchers looking to solve a similar problem, you can get a similar error if your input is an empty string.

e.g.

var d = "";
var json = JSON.parse(d);

or if you are using AngularJS

var d = "";
var json = angular.fromJson(d);

In chrome it resulted in 'Uncaught SyntaxError: Unexpected end of input', but Firebug showed it as 'JSON.parse: unexpected end of data at line 1 column 1 of the JSON data'.

Sure most people won't be caught out by this, but I hadn't protected the method and it resulted in this error.

2 of 16
28

The fact the character is a < make me think you have a PHP error, have you tried echoing all errors.

Since I don't have your database, I'm going through your code trying to find errors, so far, I've updated your JS file

$("#register-form").submit(function (event) {

    var entrance = $(this).find('input[name="IsValid"]').val();
    var password = $(this).find('input[name="objPassword"]').val();
    var namesurname = $(this).find('input[name="objNameSurname"]').val();
    var email = $(this).find('input[name="objEmail"]').val();
    var gsm = $(this).find('input[name="objGsm"]').val();
    var adres = $(this).find('input[name="objAddress"]').val();
    var termsOk = $(this).find('input[name="objAcceptTerms"]').val();

    var formURL = $(this).attr("action");


    if (request) {
        request.abort(); // cancel if any process on pending
    }

    var postData = {
        "objAskGrant": entrance,
        "objPass": password,
        "objNameSurname": namesurname,
        "objEmail": email,
        "objGsm": parseInt(gsm),
        "objAdres": adres,
        "objTerms": termsOk
    };

    $.post(formURL,postData,function(data,status){
        console.log("Data: " + data + "\nStatus: " + status);
    });

    event.preventDefault();
});

PHP Edit:

 if (isset($_POST)) {

    $fValid = clear($_POST['objAskGrant']);
    $fTerms = clear($_POST['objTerms']);

    if ($fValid) {
        $fPass = clear($_POST['objPass']);
        $fNameSurname = clear($_POST['objNameSurname']);
        $fMail = clear($_POST['objEmail']);
        $fGsm = clear(int($_POST['objGsm']));
        $fAddress = clear($_POST['objAdres']);
        $UserIpAddress = "hidden";
        $UserCityLocation = "hidden";
        $UserCountry = "hidden";

        $DateTime = new DateTime();
        $result = $date->format('d-m-Y-H:i:s');
        $krr = explode('-', $result);
        $resultDateTime = implode("", $krr);

        $data = array('error' => 'Yükleme Sırasında Hata Oluştu');

        $kayit = "INSERT INTO tbl_Records(UserNameSurname, UserMail, UserGsm, UserAddress, DateAdded, UserIp, UserCityLocation, UserCountry, IsChecked, GivenPasscode) VALUES ('$fNameSurname', '$fMail', '$fGsm', '$fAddress', '$resultDateTime', '$UserIpAddress', '$UserCityLocation', '$UserCountry', '$fTerms', '$fPass')";
        $retval = mysql_query( $kayit, $conn ); // Update with you connection details
            if ($retval) {
                $data = array('success' => 'Register Completed', 'postData' => $_POST);
            }

        } // valid ends
    }echo json_encode($data);
🌐
LambdaTest
lambdatest.com › blog › syntaxerror-json-parse-bad-parsing
SyntaxError: JSON.parse: bad parsing | LambdaTest
November 30, 2023 - In most web applications, nearly all data transferred from web server is transmitted in a string format. To convert that string into JSON, we use JSON.parse() function, and this the main function that throws errors. Nearly all JSON.parse errors are a subset of SyntaxError error type.
🌐
Reddit
reddit.com › r/phphelp › help! json syntax error in php code
r/PHPhelp on Reddit: Help! JSON Syntax Error in PHP Code
November 20, 2024 -

Hi everyone,

I'm a beginner in php and now i am currently facing an issue with a JSON syntax error in my PHP code. I've tried debugging it myself but can't seem to figure out what I'm doing wrong. Here's the part of the code where the error is coming , while this is the only code which makes the issue remaining code is correctly returning the json and my js is able to access it while in this function

function getPremiumItem($conn, $item_code)
{
    $sql = "SELECT item_name, credits FROM premium_items WHERE item_code = ?";
    $stmt = $conn->prepare($sql);
    $stmt->bind_param("s", $item_code);
    $stmt->execute();
    $item_name = '';
    $credits = 0;
    $stmt->bind_result($item_name, $credits);

    if ($stmt->fetch()) {
        echo json_encode(['item_name' => $item_name, 'credits' => $credits]);
    } else {
        echo json_encode(['error' => 'Item not found']);
    }
}

if ($_SERVER['REQUEST_METHOD'] === 'GET') {
    if (isset($_GET['action'])) {
        if ($_SERVER['action'] === 'getPremiumItem' && isset($_GET['item_code'])) {
            $item_code = $_GET['item_code'];
            getPremiumItem($conn, $item_code);
        }
    }
}

error is coming SyntaxError: JSON.parse: unexpected character at line 3 column 1 of the JSON data

can anyone pls help me fix the issue

🌐
Parabola
community.parabola.io › ask a question
JSON syntax error - Ask a question - Parabola support forum
February 13, 2023 - Keep getting this error. I’ve tried making changes as other people have had similar issues, but none have worked. Can anyone help please? Thank you for your help.
🌐
GitHub
github.com › nlohmann › json › issues › 3882
[json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal · Issue #3882 · nlohmann/json
December 15, 2022 - [json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal#3882
Author   yangkangdev
🌐
JSONLint
jsonlint.com
JSONLint - The JSON Validator
It's an excellent way to correct errors without wasting hours finding a missing coma somewhere inside your code. JSONLint is an online editor, validator, and formatting tool for JSON, which allows you to directly type your code, copy and paste it, or input a URL containing your code.
🌐
Reddit
reddit.com › r/phphelp › php thinks my json has a syntax error, but nothing else does.
r/PHPhelp on Reddit: PHP thinks my JSON has a syntax error, but nothing else does.
July 26, 2021 -

Here's the JSON:

{ "timestamp":"2021-07-19T15:42:53Z", "event":"Fileheader", "part":1, "language":"English\\UK", "Odyssey":false, "gameversion":"3.8.0.104", "build":"r269978/r0 " }

Here's the 3v4l link of it not working: https://3v4l.org/4H2gS#v8.0.8

When I say "nothing else does" I mean any online JSON validator. They all say it's valid JSON. PHP just doesn't like it.

The Weird thing is, if I open a file with that string using `fgets` `json_decode($str, true)` works.

I have these strings in an array I'm looping over, and I get NULL every damn time. I've echoed out the fgets string and pasted it into json_decode, and still no luck.

🌐
Sololearn
sololearn.com › en › Discuss › 2403202 › json-syntax-error
JSON syntax Error...... | Sololearn: Learn to code for FREE!
let students = { 0:{ "name": "K", "age": "22", "height": 155 }, 1:{ "name": "Qazi", "age": "25", "height": 156 } } console.log(JSON.stringify(students)); The Error is in the console.log(JSON.parse(students)) because you are trying to parse an array. Above is the correct syntax JSON.parse is a function which converts a Json object in string format.
🌐
JSONLint
jsonlint.com › json-parse-error
JSON Parse Error: Causes, Solutions, and Prevention | JSONLint
A JSON parse error occurs when your code attempts to convert a string into a JSON object, but the string contains invalid JSON syntax.