Help with JSon-Call within a PHP file


it´s my first try with JSon at all. I get from a platform like Digistore24 a call to a PHP-file, which includes the sales data, which I store within variables like $email.

Now I create the call like this:

$JSONString = ‘{ “email”: $email, “locale”: “de”, “fields:” [ { “Vorname”: “string”, “value”: $vorname }, { “Nachname”: “string”, “value”: $nachname }, { “Tag”: “string”, “value”: $tag } ] }’;
$JSONData = json_decode($JSONString, true);

echo $JSONData;

$JSONCall = “curl -X POST ‘’ -H ‘Content-Type: application/json’ -H ‘X-API-Key: MYAPIKEY’ -d '” . $JSONData . “'”;

$json = file_get_contents($JSONCall);

And I get this message:

SyntaxError: JSON.parse: unexpected non-whitespace character after JSON data at line 1 column 2 of the JSON data

Any idea, what´s wrong with my code?

Thanks for any hint!

Hi @disciple68,

I think you ended up in the wrong community. This forum is about JSON Forms, a Javascript based form rendering library (mostly) unrelated to server technologies like php.

Regarding your code, the problem is likely due to incorrect concatenation and encoding in your $JSONString. It seems off in general to directly construct a JSON string. As you have the variables locally available you could construct your object in place and then transform it to string via encode.

Still I would recommend seeking advice from an php expert.

Good luck!