JsonReaderException: Unexpected character encountered while parsing value: J. Path '', line 0, position 0.
Is the J. Path " an unexpected character? The file being read is filled with a JSON list of three integers.
I kept narrowing down the code to find where in this extensive function it actually fails. Because of this, there are no underlying mechanisms other than JsonReader and Debug.Log itself. This is the sequence I caught:
Debug.Log(initSettings + targetFile);
Debug.Log(JsonConvert.DeserializeObject(initSettings + targetFile));
First Debug.Log returns proper URL, I copy pasted it into run task:
notepad++ URL and intended file showed up. File isn’t empty it’s:
[
1,
5,
10
]
Second Debug.Log returns:
JsonReaderException: Unexpected character encountered while parsing value: J. Path '', line 0, position 0.
What is J. Path" and how can I get it to read actual URL?
The file might have a BOM header for UTF stuff. Do you have a hex dump program? You can dump the file out and see if it has such an infestation.
On mac you can use the xxd utility to see the byte values. A clean file should look like this:
kurtina:junk2 kurt$ cat foo.txt
[
1,
5,
10
]
kurtina:junk2 kurt$ xxd foo.txt
00000000: 5b0a 2020 312c 0a20 2035 2c0a 2020 3130 [. 1,. 5,. 10
00000010: 0a5d 0a .].
A BOM-infested file would have probably three extra bytes at the start of it. You can look online for how to strip that or else just detect it and strip it at runtime.
My hex code is vastly different.

Does it look like it has a BOM header? (That sounded pretentious and mean, I didn’t mean it). I don’t see any crazy unspecific bytes before a bracket. On top of it I saved it in UTF-8 mode, but there’s also “UTF-8-BOM”, I selected a non-BOM encoding.
No, it certainly does not.
But … it just occurred to me, I don’t think you can deserialize a “naked” array like that.
Either in the file or at runtime try doing what I suggested in this post here:
https://discussions.unity.com/t/764138
Basically you set it as a key value pair for the entire payload array.
JsonConvert.DeserializeObject Method doesn’t read from a file, it reads from a string. What is the value of initSettings + targetFile?
URL to the file. E.g. C:/Users/hmoi/Desktop/startData/players.json
Yeah that won’t work. It’s not looking for a URL or file location, where are you seeing that syntax? It’s looking for a JSON string.
For anywho who has encountered this problem.
Convert a new YourClassHere(); to JSON, then write it to the disk. This way computer will generate you absolutely valid JSON file that has the structure you want and computer won’t cry about. Make sure your class and variables inside target class are public, serialize omits non-public variables.
Now I’ll have to ask another question in another thread as this thread is absolutely unrelated.