I'm building an iOS app that frequently loads JSON configuration files at runtime. However, the files are very generous with comments and indenting. How can I tell XCode to copy minified versions of the files to the bundle during build?
Asked
Active
Viewed 948 times
1
-
JSON does not support comments. – SLaks Jul 14 '13 at 14:32
-
That's not entirely correct. While JSON with comments does not _strictly_ conform to the standard, the standard itself does not specify how comments should be handled during deserialization, so various parser implementations differ in that respect. In any case, thanks for that very insightful comment. – philtre Jul 16 '13 at 19:52
1 Answers
2
You just need to add a build phase to your target. Here is an example, my build script that converts a multimarkdown file to an HTML file.
# Create the HTML file from the Markdown File
/usr/local/bin/multimarkdown --process-html --output="${SCRIPT_OUTPUT_FILE_0}" --to=html "${SCRIPT_INPUT_FILE_0}"
# Publish the Help Text and Image to Dropbox
if [ -d ~/Dropbox/Public/DCWS-Help-Text ]; then
rsync -t "${SRCROOT}/DC Wire Sizer/en.lproj/"* ~/Dropbox/Public/DCWS-Help-Text/
fi
I create the file in the source directory but added it to my git ignore file. It is a build product and not in source control, but you need to make sure it is in your project and part of the target, so it gets copied into the bundle. Also make sure your build script runs before your copy bundle phase.

GayleDDS
- 4,443
- 22
- 23
-
Thanks, I actually did some digging and found a way to do it using Build Rules and a python script. I was able to 'minify' my files using the **demjson** python module, which can handle just about any type of JSON you throw at it. – philtre Jul 16 '13 at 19:55