readtable & json file

Discuss any general programming issues here
Post Reply
ilbarbax
Posts: 157
Joined: Thu Apr 01, 2010 6:41 pm

readtable & json file

Post by ilbarbax »

Hi,
I have two different tables and I want to save both on an unique file via writetable using the default option. They are written correctly while the reading is impossible receiving an error message. Saving the two tables, each one in a different file, they are correctly read.
There is a way to have an unique file?
plouf
Posts: 704
Joined: Sun Feb 04, 2018 11:51 pm
Location: Athens,Greece

Re: readtable & json file

Post by plouf »

cant use Seek() as said in manual to move pointer to end of first table and read next?
Christos
User avatar
jPV
Posts: 750
Joined: Sat Mar 26, 2016 10:44 am
Location: RNO
Contact:

Re: readtable & json file

Post by jPV »

ilbarbax wrote: Tue Feb 17, 2026 8:10 pm Hi,
I have two different tables and I want to save both on an unique file via writetable using the default option. They are written correctly while the reading is impossible receiving an error message. Saving the two tables, each one in a different file, they are correctly read.
There is a way to have an unique file?
Yeah, it seems that when using the "default" adapter, which writes it as JSON, it gets confused when you try to read it. The combined text file isn't in valid JSON format and serializer doesn't know how to handle it. The old "inbuilt" adapter handles this differently by reading tables as binary and continuing where the previous ended.

I have a feeling that this isn't considered as a bug, because invalid JSON in files probably isn't a good thing to keep even for this situation..

I would combine the tables into a single temporary table to solve the issue. Like this:

Code: Select all

WriteTable(1, {t1, t2}, {Adapter = "default"})
and

Code: Select all

Local temp = ReadTable(1, {Adapter = "default"})
t1 = temp[0]
t2 = temp[1]
ilbarbax
Posts: 157
Joined: Thu Apr 01, 2010 6:41 pm

Re: readtable & json file

Post by ilbarbax »

@JPV

You got it right. as usual a really elegant solution.
thanks
Post Reply