JSON DATA CORRUPTED ERROR

I don't why, my json file is throwing an error as being corrupted even though json file is valid. (I have checked from json validator). Here is my code: My model:

`import Foundation

class Person:Identifiable,Decodable{

    var id:UUID?

    var Name:String

    var Address:String

    var Company:String

    var YearsofExperience:Int

}

My JSON File

[{

    "Name":"Inigo Montoya",

   "Address":"555 YouKilled My father Street",

   "Company":"CodeWithChris",

   "YearsofExperience":35

 },

 {

     "Name":"Edna Mode",

    "Address":"123 Nocape Lane",

    "Company":"CodeWithChris",

    "YearsofExperience":177

 },

 {

     "Name":"Travis Bickle",

    "Address":"99 Youtalkingtome Road",

    "Company":"CodeWithChris",

    "YearsofExperience":99

 },

 {

     "Name":"Walter Sobchak",

    "Address":"8 Dude Place",

    "Company":"CodeWithChris",

    "YearsofExperience":23

    

 },

 {

     "Name":"Jullis Winnfield",

    "Address":"25 Ezekiel Ave",

    "Company":"CodeWithChris",

    "YearsofExperience":17

 }]

ViewModel:

import Foundation

class EmployeeModel:ObservableObject{
@Published var person = [Person]()
init(){

    person.self = DataFetching.getLocalData()

}
}
Answered by Scott J in 702863022

The error message "Invalid value around line 1, column 0." is consistent with having invalid bytes at the very start of the file. Maybe there are some non-printing (invisible) characters there for some reason? (I initially thought byte order mark, but that seems to work fine.) Try examining the file directly via this command:

$ hexdump -C <path-to-your-JSON-file> | head -1

The expected output is exactly this:

00000000  5b 7b 0a 20 20 20 20 22  4e 61 6d 65 22 3a 22 49  |[{.    "Name":"I|

If the first character isn’t the opening square bracket, that’s bad. Let us know what it shows.

Is it possible to upload the json data file, like this?

it is not allowing me to post any code or attachments . i created the json file inside the project so the path should not be a problem?

Accepted Answer

The error message "Invalid value around line 1, column 0." is consistent with having invalid bytes at the very start of the file. Maybe there are some non-printing (invisible) characters there for some reason? (I initially thought byte order mark, but that seems to work fine.) Try examining the file directly via this command:

$ hexdump -C <path-to-your-JSON-file> | head -1

The expected output is exactly this:

00000000  5b 7b 0a 20 20 20 20 22  4e 61 6d 65 22 3a 22 49  |[{.    "Name":"I|

If the first character isn’t the opening square bracket, that’s bad. Let us know what it shows.

JSON DATA CORRUPTED ERROR
 
 
Q