Save data not valid JSON data

Discussion and help for Easy Save 3

Save data not valid JSON data

Postby Mephialtes » Thu Jul 11, 2019 10:39 pm

Hi,

The save data is supposed to be in JSON format right? Json requires keys to be of string value. So the references section is not valid JSON, but is valid Javascript. Correct? I get invalid JSON data if I run my save data through a JSON validator or try to upload it via MongoDB/Gamesparks. Validator also complains about the duplicate keys. Is there are reason there are redundant reference keys? Am I missing something here? Maybe I am doing something wrong?

Code: Select all
"refs": {
                        6147145229505087519: 3964229153413227941,
                        4521407926050164919: 4659916949074820127,
                        8887981038426738068: 4643818365326633771,
                        7801241180676595045: 6921372454578113569,
                        8923448534021399793: 7956435598951315519,
                        5570216808131158380: 4768265553882149349,
                        7877142826183025678: 5591654673665376385,
                        5345796206498488671: 6412893998947204893,
                        2167628286546691924: 6219355446107117514,
                        276950469008270729: 252737232781144338,
                        5338633883861783119: 5343559685816861343,
                        9090583446478808596: 7848895201614759870,
                        1603433101364634735: 1613756695314031369,
                        5433670845306800592: 4354059782613773896,
                        682969862155666183: 6987914355961062697,
                        4152894498186591839: 2510128833087897508
                     }
Attachments
Capture2.PNG
Capture2.PNG (10.26 KiB) Viewed 25 times
Capture.PNG
Capture.PNG (4.43 KiB) Viewed 28 times
Mephialtes
 
Posts: 5
Joined: Sat Jun 08, 2019 10:41 pm

Re: Save data not valid JSON data

Postby Joel » Fri Jul 12, 2019 5:07 pm

Hi there,

When storing Dictionaries we break the validity of JSON to improve performance and readability. To remain valid with JSON, Dictionaries would need to be represented as an array of objects with separate key/value fields, which would increase the overhead quite significantly, and is quite difficult to read.

With regards to duplicate keys, there is nothing in the standard which says that this isn't allowed (see https://stackoverflow.com/questions/218 ... -an-object). This will only be imposed by the serialiser/deserialiser you are using, and Easy Save does not impose this restriction.

Easy Save's JSON data isn't intended to be parsed by anything other than Easy Save. If you want to upload the data to a database, you should upload and store the JSON as a string, rather than trying to parse it.

All the best,
Joel
Joel Tebbett @ Moodkie Interactive
Twitter - Unity - LinkedIn
User avatar
Joel
Moodkie Staff
 
Posts: 2336
Joined: Wed Nov 07, 2012 10:32 pm


Return to General Discussion

Who is online

Users browsing this forum: Bing [Bot] and 5 guests