jtools update

Aug 24, 2010 18:10

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: 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.

json, computers, jtools, programming, beware the geek, perl

Previous post Next post
Up