Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Working with Large JSON File

ANSWERED

I'm in the middle of recreating a Bible App. My original bible app worked, but was a little messy because it was built before Dynamic Tilesets and Dynamic Textarea was available within the SDK. 

 

Originally when the user selected a verse the app would fetch the verse from http://bible-api.com/. This worked pretty well, but I'd prefer not to make a bunch of API calls. It would be nice if the app would work offline.

 

I thought a good solution might be to store the Bible on the Device its self. The JSON for the entire Bible is ~6MBs. So the question I have is: How do I access information within a Large JSON without running out of memory on the watch?

 

I've had a couple of thoughts:

1) Break the files up into Chapters and store them in ~1,200 files.

2) Store the Books on the phone and use its processing power to load and update the watch.

3) Maybe there is a clever way to stream the JSON --> Find the Location I need --> And then Start Loading Text from that location.

4) If there is some sort of way to access a specific location in a file --> Make a JSON Key that stores the position start and stop of each verse.   

 

I don't know which of the above are doable? 

 

Any help is much appreciated,

-Don

 

 

Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions

There isn't an API for random access with JSON, but there is for random access in binary files. You'll have to handle indexing yourself, and beware multi-byte characters.

 

Uploading 6MB to the watch would take quite a while, I think. Do some tests.

 

Really, you should aim to do as much heavy lifting as you can on the companion. However, with the flakiness of companion-device comms, I sympathise.

 

Read up on the watch's storage limits. You'll also have to be careful about responsiveness; if your app takes too long to do something without taking a breather, it will... be glad it had faith. 😉

Peter McLennan
Gondwana Software

View best answer in original post

Best Answer
3 REPLIES 3

There isn't an API for random access with JSON, but there is for random access in binary files. You'll have to handle indexing yourself, and beware multi-byte characters.

 

Uploading 6MB to the watch would take quite a while, I think. Do some tests.

 

Really, you should aim to do as much heavy lifting as you can on the companion. However, with the flakiness of companion-device comms, I sympathise.

 

Read up on the watch's storage limits. You'll also have to be careful about responsiveness; if your app takes too long to do something without taking a breather, it will... be glad it had faith. 😉

Peter McLennan
Gondwana Software
Best Answer

Thank you for the quick reply. Do you have an example of random accessing a binary file?

 

Thank you,

-Don

Best Answer
0 Votes

I've used it and it works fine. My code isn't good enough to be helpful, though. 🙂 Plus, I used it for binary data (raw number arrays); you'll need to be smarter if you're using text/JSON/unicode/UTF...

 

Doco is here.

Peter McLennan
Gondwana Software
Best Answer
0 Votes