# Unexpected character at line 1 column 1 of the JSON data

**URL:** <https://developer.squareup.com/forums/t/unexpected-character-at-line-1-column-1-of-the-json-data/7382>\
**Category:** Questions\
**Tags:** web-payments-sdk\
**Created:** [October 27, 2022, 3:50am UTC](https://developer.squareup.com/forums/t/unexpected-character-at-line-1-column-1-of-the-json-data/7382 "2022-10-27T03:50:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![smobilesoft](https://avatars.discourse-cdn.com/v4/letter/s/a5b964/32.png) [@smobilesoft](https://developer.squareup.com/forums/u/smobilesoft)\
**Post date:** [October 27, 2022, 3:50am UTC](https://developer.squareup.com/forums/t/unexpected-character-at-line-1-column-1-of-the-json-data/7382/1 "2022-10-27T03:50:34Z")

</div>

Hi,

My customer was using square payment until the start of this year.  
The code that I manage to build, some time ago, stop working asking for a “CARD\_DECLINED\_VERIFICATION\_REQUIRED”.

I decided to move to the latest api version and download the latest example.

So …. I :  
a) used composer to download the latest SDK and copy the vendor folder in my server  
b) changed the version targeting at the dashboard  
c) download the connect-api-examples-master/connect-examples/v2/php\_payment/ code  
d) remove the Dotenv library and hard-code the credentials in the code

at the createPayment async function I am get the error: ”Error: SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data”

this is the result of the JSON.stringify({token}) -\>{“token”:“cnon:CBASEHliYZ8p\_8S3lesvM7sftsk”}

APPLICATION\_ID:sandbox-sq0idb-1sdAosroBG2XGsq8wGuL3w

Can somebody, please, help me?  
Thank you  
Alex

---

<div class="post-metadata">

**Author:** ![Bryan-Square](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/bryan-square/32/38_2.png) [@Bryan-Square](https://developer.squareup.com/forums/u/Bryan-Square)\
**Post date:** [October 27, 2022, 4:34pm UTC](https://developer.squareup.com/forums/t/unexpected-character-at-line-1-column-1-of-the-json-data/7382/2 "2022-10-27T16:34:56Z")

</div>

Was the example in a working state prior to you making any changes? If so what was the change that broke the example. 🙂

---

<div class="post-metadata">

**Author:** ![smobilesoft](https://avatars.discourse-cdn.com/v4/letter/s/a5b964/32.png) [@smobilesoft](https://developer.squareup.com/forums/u/smobilesoft)\
**Post date:** [October 27, 2022, 5:36pm UTC](https://developer.squareup.com/forums/t/unexpected-character-at-line-1-column-1-of-the-json-data/7382/3 "2022-10-27T17:36:05Z")

</div>

Hi,  
I dont think I broke the example, the only changes that I have done is to bypass the Dotenv library.  
I think I can handle that. 🙂

location-info.php is working fine

inside the sq-payment-flow.js the createPayment function returns the error

Error: SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data [square.js:formatted:5890](https://sandbox.web.squarecdn.com/v1/square.js:formatted)  
ke square.js:5890  
and the following code is your square.js code is crashing inside the “case ‘console’” at the  
“t && t.apply(xe.console, r)”

```auto
   function ke(e, t) {
      Ue[e] = Ue[e] || [
      ],
      Ue[e].push(t),
      function (e) {
        if (!Me[e]) switch (Me[e] = !0, e) {
          case 'console':
            'console' in xe && X.forEach((function (e) {
              e in xe.console && G(xe.console, e, (function (t) {
                return function (...r) {
                  He('console', {
                    args: r,
                    level: e
                  }),
                  t && t.apply(xe.console, r)
                }
              }))
            }));
            break;

```

```auto
window.createPayment = async function(token) {
  const dataJsonString = JSON.stringify({
    token
  });

  try {
      const response = await fetch('https://mymadrasah.co.uk/123456/process-payment.php', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json'
      },
      body: dataJsonString
    });

    const data = await response.json();

    if (data.errors && data.errors.length > 0) {
      if (data.errors[0].detail) {
        window.showError(data.errors[0].detail);
      } else {
        window.showError('Payment Failed.');
      }
    } else {
      window.showSuccess('Payment Successful!');
    }
  } catch (error) {
    console.error('Error:', error);
  }
}

```

location-info.php

```auto
<?php

// Note this line needs to change if you don't use Composer:
// require('square-php-sdk/autoload.php');
require 'vendor/autoload.php';

// use Dotenv\Dotenv;
use Square\SquareClient;

// dotenv is used to read from the '.env' file created for credentials
// $dotenv = Dotenv::create(dirname( __DIR__ ));
// $dotenv->load();

// The access token to use in all Connect API requests.
// Set your environment as *sandbox* if you're just testing things out.

class LocationInfo {
  // Initialize the Square client.
  var $currency;
  var $country;
  var $location_id;

  function __construct() {
    //$access_token = getenv('SQUARE_ACCESS_TOKEN');
    $access_token = "EAAAENUaCQNZuTd4ugz7nzrs-86RFjVUxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

    // 'environment' => getenv('ENVIRONMENT')
    $this->square_client = new SquareClient([
      'accessToken' => $access_token,  
      'environment' => "sandbox"
    ]);
    // $location = $this->square_client->getLocationsApi()->retrieveLocation(getenv('SQUARE_LOCATION_ID'))->getResult()->getLocation();
    $location = $this->square_client->getLocationsApi()->retrieveLocation("31M5Txxxxxxxx")->getResult()->getLocation();
    $this->location_id = $location->getId();
    $this->currency = $location->getCurrency();
    $this->country = $location->getCountry();  
  }

  public function getCurrency() {
    return $this->currency;
  }

  public function getCountry() {
    return $this->country;
  }

  public function getId() {
    return $this->location_id;
  }
}

$location_info = new LocationInfo();

?>

```

index.php

```auto
<?php
require 'vendor/autoload.php';
include 'utils/location-info.php';

use Square\Environment;
// dotenv is used to read from the '.env' file created for credentials
// $dotenv = Dotenv\Dotenv::create( __DIR__ );
// $dotenv->load();

// Pulled from the .env file and upper cased e.g. SANDBOX, PRODUCTION.
// $upper_case_environment = strtoupper(getenv('ENVIRONMENT'));
$upper_case_environment = "SANDBOX";
//$web_payment_sdk_url = $_ENV["ENVIRONMENT"] === Environment::PRODUCTION ? "https://web.squarecdn.com/v1/square.js" : "https://sandbox.web.squarecdn.com/v1/square.js";
$web_payment_sdk_url = "https://sandbox.web.squarecdn.com/v1/square.js";

?>
<html>

<head>
  <title>My Payment Flow</title>
  <!-- link to the Square web payment SDK library -->
  <script type="text/javascript" src="<?php echo $web_payment_sdk_url ?>"></script>
  <script type="text/javascript">
    window.applicationId =
      "<?php
        // echo getenv('SQUARE_APPLICATION_ID');
        echo "sandbox-sq0idb-1sdAosroBG2XGsq8wGuL3w";
        ?>";
    window.locationId =
      "<?php
        // echo getenv('SQUARE_LOCATION_ID');
        echo "31M5T28Sxxxxxxx";
        ?>";
    window.currency =
      "<?php
        echo $location_info->getCurrency();
        ?>";
    window.country =
      "<?php
        echo $location_info->getCountry();
        ?>";
  </script>
  <link rel="stylesheet" type="text/css" href="public/stylesheets/style.css">
  <link rel="stylesheet" type="text/css" href="public/stylesheets/sq-payment.css">
</head>

<body>
  <form class="payment-form" id="fast-checkout">
    <div class="wrapper">
      <div id="apple-pay-button" alt="apple-pay" type="button"></div>
      <div id="google-pay-button" alt="google-pay" type="button"></div>
      <div class="border">
        <span>OR</span>
      </div>
      <div id="ach-wrapper">
        <label for="ach-account-holder-name">Full Name</label>
        <input id="ach-account-holder-name" type="text" placeholder="Jane Doe" name="ach-account-holder-name" autocomplete="name" /><span id="ach-message"></span><button id="ach-button" type="button">Pay with Bank Account</button>

        <div class="border">
          <span>OR</span>
        </div>
      </div>
      <div id="card-container"></div><button id="card-button" type="button">Pay with Card</button>
      <span id="payment-flow-message"></span>
    </div>
  </form>

  <script type="text/javascript" src="public/js/sq-ach.js"></script>
  <script type="text/javascript" src="public/js/sq-apple-pay.js"></script>
  <script type="text/javascript" src="public/js/sq-card-pay.js"></script>
  <script type="text/javascript" src="public/js/sq-google-pay.js"></script>
  <script type="text/javascript" src="public/js/sq-payment-flow.js"></script>
</body>
</html>

```

---

<div class="post-metadata">

**Author:** ![bdg2017](https://avatars.discourse-cdn.com/v4/letter/b/898d66/32.png) [@bdg2017](https://developer.squareup.com/forums/u/bdg2017)\
**Post date:** [November 11, 2022, 8:46pm UTC](https://developer.squareup.com/forums/t/unexpected-character-at-line-1-column-1-of-the-json-data/7382/4 "2022-11-11T20:46:43Z")

</div>

JSON.parse: unexpected character at line 1 column 1 of the JSON data on this page. [https://www.bigdippergraphics.com/public/examples/card.php](https://www.bigdippergraphics.com/public/examples/card.php)

I’m lost, all I did was update the the sandbox id and location

---

<div class="post-metadata">

**Author:** ![Bryan-Square](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/bryan-square/32/38_2.png) [@Bryan-Square](https://developer.squareup.com/forums/u/Bryan-Square)\
**Post date:** [November 11, 2022, 8:58pm UTC](https://developer.squareup.com/forums/t/unexpected-character-at-line-1-column-1-of-the-json-data/7382/5 "2022-11-11T20:58:30Z")

</div>

Hmm, everything looks good from what I see. Did you follow all the steps in the README.md? 🙂
