Quick 'n Dirty JSON Concatenation/Compression utility
I needed a way to take a bunch of JSON files needed by an iOS app, put them together (and preferably compress them) to coalesce disk seeks into a single efficient one. I added Build Phase that calls this script like this :
/usr/local/bin/node /usr/local/share/npm/bin/jaysoned ${BUILT_PRODUCTS_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/ ${BUILT_PRODUCTS_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/json.snz
rm ${BUILT_PRODUCTS_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/*.json
- Which basically looks for all
.json
files in the unlocalized resource location of the app's product directory, hands them tojaysoned
and removes them when done. jaysoned
parses them and makes one, larger JSON file with keys being the original files' names, and values being the files' contents as javascript objects.- Then, it takes the resulting large js object, stringifies it, compresses it using Snappy, Google's fast compression
library and writes the result to
json.snz
, jaysoned's second argument.
The app, as soon as one of these JSON objects is needed, reads the file, uncompresses it using Snappy-ObjC and caches the resulting JSON object for later use.