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)

4
  • I doubt that browsers will even let you store GBs of data just like that. And that is not even considering the bad user experience. Commented Aug 22, 2023 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. Commented Aug 23, 2023 at 3:37
  • Ooh.. just did the search myself. jaxon looks promising as well: npmjs.com/package/jaxon Commented Aug 23, 2023 at 3: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? Commented Aug 28, 2023 at 15:12

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.