The Life Unwired with Ben Combee (unwiredben) wrote,
The Life Unwired with Ben Combee
unwiredben

Comment Hack for appinfo.json

I really like JSON.  It's easy to write, easy to parse, and more compact than XML, and it works great as a way to pass around method parameters and return values.  However, it has a big flaw -- there is no way to write a comment in a JSON file.  The // and /* */ syntax used by JavaScript isn't supported, so many JSON parsers will reject files that have them.

Every application on Palm webOS comes with an appinfo.json file that describes key information like it's title, where it's icon lives, and it's application ID.  For some samples I'm doing, I'd like to write some comments in appinfo.json so people know where to change the values for their application.  However, I spotted a way out.  Deep in our documentation, we note that this file can contain other JSON attributes beyond what we specify.  So, I realized that no one has to use those elements, and if you name them something ridiculous like "// c1", they're unlikely to ever conflict with an application's use.  So now, I can write things like

{
   "// c1": "The next attribute, id, defines the permanent ID for your program. Change it!",
   "id" : "com.palmdts.example",
   ...
}

without invoking the wrath of the JSON parsers.
Tags: json, palm, technology, webos
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 1 comment