0

I'm working on a static website (hosted on GitHub pages for now) that's a Svelte PWA (Progressive Web App). A Svelte component on my main page needs to access and display some text from large json files without loading the entire file into memory. The files will be already on the device as the PWA will be downloading them before allowing the user to use them. Is there a way/library in javascript to search the json file for just one nested object or array and then only load that into memory to display?

I looked already for existing questions on this issue, and found solutions for Python and Java, but not JS (Python: Reading rather large JSON files and Java: how to parse a huge JSON file without loading it in memory)

C Parks
  • 1
  • 1
  • I doubt that browsers will even [let you store GBs of data](https://stackoverflow.com/questions/58591353/how-much-can-a-pwa-store) just like that. And that is not even considering the bad user experience. – H.B. Aug 22 '23 at 16:50
  • Search for the term "json sax" on npm. SAX based parsers came from the days of huge XML documents/datasets and is based on calling your callback for each data in the document. Because of this it can process streams rather than complete documents. I've used `stream-json` before. `clarinet` is another popular library though I've never used it. – slebetman Aug 23 '23 at 03:37
  • Ooh.. just did the search myself. `jaxon` looks promising as well: https://www.npmjs.com/package/jaxon – slebetman Aug 23 '23 at 03:39
  • @slebetman thanks for the response, looks promising! However, I'm a bit confused how to use this in my project as I'm targeting for the web environment (not node) and am unsure how to use jaxon for that? Like would I try to strip the contents of the lib within the node modules and then move it into my project src? – C Parks Aug 28 '23 at 15:12

0 Answers0