January 2018

S M T W T F S
  123456
78910111213
14151617181920
21222324252627
28293031   

Style Credit

Expand Cut Tags

No cut tags
pozorvlak: (Default)
Tuesday, August 24th, 2010 06:10 pm
I've updated the JSON utilities first described here. Changes:
  • jd outputs JSON, as it should really have done all along. It's now an even thinner wrapper around Makamaka Hannyaharamitu's excellent JSON module :-)
  • jf now has a -p option that pretty-prints its output directly.
  • jf can now handle several field specifiers at once, and preserves enough of the structure of the input to contain them all. Here's an example:
    $ curl -s -upozorvlak:<my password here> http://api.twitter.com/1/statuses/mentions.json \
    | jf -p user/name user/screen_name text
    [
       {
          "text" : "@pozorvlak I have to admit that if you have polymorphism then
                   things like +. are particularly pointless.",
          "user" : {
             "name" : "Christopher Yocum",
             "screen_name" : "cyocum"
          }
       },
       {
          "text" : "@pozorvlak Huh, I still like the safety that static typing gives you.",
          "user" : {
             "name" : "Christopher Yocum",
             "screen_name" : "cyocum"
          }
       }
    ... etc ...
    ]
    The XPathy syntax is due to Leon Timmermans.
You can download the source or check it out from GitHub. All suggestions (or better, patches!) gratefully received.

So, what else could I do to make these useful? One option would be to allow a wider range of XPath selectors - currently only the child axis is supported - but I'm not sure how to do that and preserve the structure of the input, which is essential for the kind of thing I use jf for. I could certainly document the programs better. For now, though, I think I'll email Makamaka and ask if he'd be interested in including jf in the JSON.pm distribution.
pozorvlak: (Default)
Saturday, June 13th, 2009 12:33 pm
Probably everyone who's spent more than five minutes working with web services and JSON has versions of these utilities. Here are mine.

jd: JSON pretty-printer/dumper )

jf: extract fields from (lists of) JSON objects )

I gratefully acknowledge the generosity of my employers (for whom I do not speak...) for allowing me to release these programs despite them being written during work hours. Thanks!