phpjsongwtutf-8jsonlint

Trying to parse a JSON string, but always fails


This piece of JSON right here:

{"user":[{"idUser":"1","username":"USERNAME","userFullName":"FULL NAME","userEmail":"EMAIL@MAIL.COM"}]}

Does not validate in jsonlint also not with GWT.

What is strange is that if I delete the first curly brace and type it again, it returns as valid. Here is the error it gives:

Parse error on line 1:
{    "user": [   
^
Expecting '{', '['

Any reason for this? Note that I'm using PHP to generate this string. PHP file used is UTF-8 encoded.


Solution

  • Thanks to @knittl for noticing it.

    I had the php file encoded in UTF-8.

    I changed it to UTF-8 without BOM and it worked. I suppose some "garbage" was being returned when I was copying it to jsonlint.