 <p>Why don't you use a framework for that job?</p> <p>You can try json-framework (formerly SBJSon).</p> <p>Project page : <a href="https://github.com/stig/json-framework" rel="nofollow">https://github.com/stig/json-framework</a></p>