Add in JSON Array
-
wrote on 30 Oct 2018, 10:59 last edited by
Hi!
There is the array in json-file. In need to add ther other element of this array. But it takes a lot of time to load whole array. How can I add one element quickly? -
Hi!
There is the array in json-file. In need to add ther other element of this array. But it takes a lot of time to load whole array. How can I add one element quickly?wrote on 30 Oct 2018, 11:46 last edited byHi @Mikeeeeee,
please provide some more information. Do you use
QJsonDocument
or javascript JSON in qml? Can you provide a minimal example? -
wrote on 30 Oct 2018, 14:47 last edited by
Yes, I use QJsonDocument. There is only one array in json file. There is QString LastResume in my project. I would like to add LastResume in the array in json file. But json file may be is large. That's why I don't want load the whole file.
-
wrote on 30 Oct 2018, 15:04 last edited by
Since JSON is a text file, you maybe faster in creating two
QTextStream
, one for reading your JSON file, and one for writing to a new file. You can process the input file line by line until you hit the array end character]
, where you can insert your string. This is kind of change by copy. But I don“t know if this is really faster, you have to try.Maybe someone else here has experience in modifying large files. Maybe this can be faster with memory mapping the file?
-
Hi
What Qt version are you using ?
The array must be ULTRA huge for it to take time.
https://bugreports.qt.io/browse/QTBUG-44737so i wonder if its older Qt version.
-
wrote on 31 Oct 2018, 08:32 last edited by
My version 5.11.2
json file can occupy several gigabytes
-
@Mikeeeeee said in Add in JSON Array:
json file can occupy several gigabytes
!
Wondering what the use case for such huge JSON file is... -
wrote on 31 Oct 2018, 10:17 last edited by
I predicted to use it for saving array. But I desided to use SQL.
-
@Mikeeeeee
Using SQL is way better as a JSON file this size will consume TONS of memory with a DOM parser like QJsonDocument. -
QJson also has an internal memory limit which is imo below 1GB. There was a thread about this on the mailing list some months ago (during the cbor introduction iirc)
-
QJson also has an internal memory limit which is imo below 1GB. There was a thread about this on the mailing list some months ago (during the cbor introduction iirc)
@Christian-Ehrlicher said in Add in JSON Array:
QJson also has an internal memory limit which is imo below 1GB. There was a thread about this on the mailing list some months ago (during the cbor introduction iirc)
That limit (128 MB) is for saving to binary JSON only, if I recall correctly.
8/11