Why JSON files sometimes fail after Save?

Discuss any general programming issues here
Bugala
Posts: 1390
Joined: Sun Feb 14, 2010 7:11 pm

Why JSON files sometimes fail after Save?

Post by Bugala »

I keep getting this problem constantly, and I dont know where the problem actually is.

But quite often when I do something with my JSON-file, and I then try run my Hollywood program that uses the JSON-file, I start getting this: "Error deserializing item!".

And this happens even there is no apparent error in my JSON file.

To give example, I just altered my JSON-file to try a new thing, and I got the error. Then I used "Undo"-option, to get back all the way to the same it was, saved, and yet, I still get the Deserialize error again.

Therefore I suppose the error happens when saving the file. I have used Visual Studio Code to edit the file, and also used the Save As, and used the option "JSON file", and yet still it keeps getting the deserialize problem.

What is the root cause of the problem, since this keeps happening, regardless if I use Hollywood or Visual Studio Code to save the file.
Flinx
Posts: 342
Joined: Sun Feb 14, 2021 9:54 am
Location: Germany

Re: Why JSON files sometimes fail after Save?

Post by Flinx »

I don't think you'll get a helpful answer to this kind of question.
Isn't it possible to provide an example?
Bugala
Posts: 1390
Joined: Sun Feb 14, 2010 7:11 pm

Re: Why JSON files sometimes fail after Save?

Post by Bugala »

Here an example:

Hollywood Code:

Code: Select all

SetDefaultAdapter(#ADAPTER_SERIALIZE, "default")

File = "example.json"
OpenFile(1, File, #MODE_READ)
	Local StoryFile = ReadTable(1)
 CloseFile(1)
JSON-Code:

Code: Select all

{
}
Here the Example JSON-File saved in Visual Studio Code, using "Save As", and choosing "JSON" as the file format: https://www.dropbox.com/scl/fi/zgu4kr63 ... x7aqi&dl=0

Point being that this is the simplest possible JSON-table, an empty table, so shouldnt be error in the JSON-code as far as I know, yet, when I try to run this code, it gives me the "Error deserializing item!"

What am I doing wrong? Sometimes it seems to work, and sometimes not. I edit the file just little, save it, and it starts doing this.

Windows 11, Hollywood 10.
Flinx
Posts: 342
Joined: Sun Feb 14, 2021 9:54 am
Location: Germany

Re: Why JSON files sometimes fail after Save?

Post by Flinx »

Hi Bugala,
I've tried a lot of things now, and I can't get ReadTable() to report an error with a valid JSON file. Was the “Error deserializing item!” really reported with this empty table?
Bugala wrote: Fri Sep 12, 2025 8:54 pm I edit the file just little, save it, and it starts doing this.
Are you changing the JSON file manually?
Bugala
Posts: 1390
Joined: Sun Feb 14, 2010 7:11 pm

Re: Why JSON files sometimes fail after Save?

Post by Bugala »

Did you download that file from dropbox?

For point is not that I cant read, for example, empty table, at all. But only that after I alter the file, then save it with Hollywood IDE or Visual Studio Code (havent tried anything else), then it starts failing, even if I edit it to just to an empty table.

Strangely, when I copy-paste the code from ChatGPT, save it the first time, it usually works. But after I manually edit the file, then save it, it stops working.

Here is a video to demonstrate that I really am using the file in the dropbox, and it fails: https://youtu.be/a9x-_lXt6-4

Notice that I did do some cutting to shorten the video. My machine was doing other stuff on background at same time, and hence things happened bit slow.

1. Video starts by me running the program, and it fails, since JSON-file is missing from the folder. I am doing this by purpose, to make sure that there is no possibility of me starting a wrong program, or having different file or something.

2. I show the folder which contains the Hollywood program, and this shows that there is no JSON-file there at this point.

3. I go to this topic, link the Dropbox link in this thread, and download the file. This also shows the contents of the file, which, as you can see, is simply an empty table.

4. I go to downloads folder and transfer the file to the folder which contains the program (which, before, didnt have that JSON-file, or anything else either, but the Hollywood code)

5. I show that the folder now contains this JSON-file.

6. I go to Hollywood IDE, use "save as" so that it shows the location where the currently open program resides. You can see that this is exactly the same location, as is the location that I am showing in resource management, by other words, the location where I just transferred the JSON-file.
Notice that i dont actually Save the file. Therefore file is exactly same as the one I ran at beginning of the video.

7. Now I run the program, and it gives me the "Error deserializing item!". Notice, that this is exactly same program I executed at start of video, when it was complaining that the file was not found. That it now finds a file, is additional proof that this is the JSON-file that I just downloaded, since otherwise it should complain of not finding the file again.

Hence. It is an empty table, and it fails, but why?

And is this problem only when I run it, or with others too. That did you download the file from Dropbox? Since it is specifically this file that needs to be tested, since I am convinced that something must be happening to this file when I am saving it, unless there is some strange bug in Hollywood that affects maybe HW10 Win11 combination only.
Flinx
Posts: 342
Joined: Sun Feb 14, 2021 9:54 am
Location: Germany

Re: Why JSON files sometimes fail after Save?

Post by Flinx »

Bugala wrote: Sat Sep 13, 2025 5:18 pm Did you download that file from dropbox?
Sorry, no, because I erroneously thought I had to register, so I only did copy and paste.
Now I have downloaded it, could reproduce the problem and found the reason. Your file is UTF-8-BOM coded, and ReadTable() don't like that.
I think this is a bug.

Ralf
Bugala
Posts: 1390
Joined: Sun Feb 14, 2010 7:11 pm

Re: Why JSON files sometimes fail after Save?

Post by Bugala »

Thanks a dozen! Finally some reasonable explanation.

I thought it was adding some extra code somewhere that I just didnt know how to get it to show it or something, since some formats might do that, but I was wondering that how on earth would it add some extra line to JSON-files, since that would make no sense. But different encoding format. That makes sense, and wouldnt be noticeable by having extra characters.


@Andreas

Can you confirm that this is not intended behavior and get it fixed?
Bugala
Posts: 1390
Joined: Sun Feb 14, 2010 7:11 pm

Re: Why JSON files sometimes fail after Save?

Post by Bugala »

@Flinx

Thanks one more time. This problem been annoying me for a long time, and delayed my coding a lot.

I can confirm that problem seems to be exactly what you said. I found a way to save a file in different encoding with Visual Studio Code, and now it opened it with no problem at all. Just had to change it away from UTF-8 BOM to just UTF-8.
Flinx
Posts: 342
Joined: Sun Feb 14, 2021 9:54 am
Location: Germany

Re: Why JSON files sometimes fail after Save?

Post by Flinx »

Great.
I've meanwhile written a BOM-safe ReadTable(), and even though you don't need it anymore, I don't want to just delete it. Here it is:

Code: Select all

Function p_ReadTable(id)
	Local rv
	Local data$=ReadBytes(id,3)
	If ByteAsc(data$, 0)=0xEF And ByteAsc(data$, 1)=0xBB And ByteAsc(data$, 2)=0xBF
		Seek(id, 3)
		rv=ReadTable(id)
	Else
		Seek(id, 0)
		rv=ReadTable(id)
	EndIf
	Return(rv)
EndFunction
Bugala
Posts: 1390
Joined: Sun Feb 14, 2010 7:11 pm

Re: Why JSON files sometimes fail after Save?

Post by Bugala »

Actually, this might come useful, depending how fast Andreas going to fix the problem.

For reason to move towards JSON-format instead of Hollywoods own Tables is to give users a chance to alter the files or even make their own custom stories for example for the games.

Hence while I know how to get around this problem, it is not ideal that if someone wants to make his own level for example, which might be first steps into "programming", that he should face the additional hardship of figuring out that he needs to save the files in some certain encoding.

Going to save your ReadTable version, and possibly use it.
Post Reply