JSON history - string vs object

I'm working with large json structures and have to keep a few steps of JSON history. I am wondering whether its better to just have an array with json objects or stringifying and adding the string to the array instead? My brain tells me it should be better stringified.
7 Replies
MartynasXS
MartynasXSOPβ€’8mo ago
Or i can try looking into some JSON diffing to make it more memory efficient
dys πŸ™
dys πŸ™β€’8mo ago
For speed and ease of access, I'd expect the parsed version to be more effective. For space efficiency, it depends on what sort of data you have. If you're storing lots numbers, the parsed version will be 8 bytes and the string version will be 1 byte per character. If you've got lots of strings, the storage will be about the same, but you'll be doing away with the pointers between objects. How big is "large"? Recall that small images are dozens of kibibytes. The space you save by serializing isn't going to be all that much though, and I wouldn't think it'd be worth it. The ideal would be some sort of representation of actions taken with the ability to reverse them. If you find a good diffing algorithm, post it. I've been contemplating a distributed graph database & would love a solid method for succinctly expressing differences in state.
MartynasXS
MartynasXSOPβ€’8mo ago
the one im looking at rn is 11MB it has a good mix of numbers and strings
Chooβ™šπ•‚π•šπ•Ÿπ•˜
Why are you not using a database?
MartynasXS
MartynasXSOPβ€’8mo ago
why would i store json in the database
Chooβ™šπ•‚π•šπ•Ÿπ•˜
No. I meant storing the data in a database not in JSON at all.
MartynasXS
MartynasXSOPβ€’8mo ago
its not exactly data its almost like code in json format so its not uniform or storable in a db table unless you make an incredibly complicated db
Want results from more Discord servers?
Add your server