Softpedia
 


LINUX CATEGORIES:



GLOBAL PAGES >>
NEWS ARCHIVE >>
SOFTPEDIA REVIEWS >>
MEET THE EDITORS >>
WEEK'S BEST
  • Linux Kernel 3.9.6 / 3....
  • Linux Kernel 3.0.82 LTS...
  • KDE Software Compilatio...
  • PulseAudio 4.0
  • Wireshark 1.10.0
  • NetworkManager 0.9.8.2
  • LibreOffice 3.6.6 / 4.0...
  • SystemRescueCd 3.7.0
  • Linux Kernel 3.10 RC6
  • Ubuntu Tweak 0.8.5
  • Home > Linux > Programming > Libraries

    jsongrep 0.1.1

    Download button

    No screenshots available
    Downloads: 221  View global page NEW!  Tell us about an update
    User Rating:
    Rated by:
    Excellent (5.0/5)
    2 user(s)
    Developer:

    License / Price:

    Last Updated:

    Category:
    David Schoonover | More programs
    MIT/X Consortium Lic... / FREE
    January 29th, 2010, 16:03 GMT
    ROOT / Programming / Libraries

     Read user reviews (0)  Refer to a friend  Subscribe

    jsongrep description

    Search and select bits out of a JSON document

    jsongrep is a command-line utility for extracting values from JSON documents. It supports shell-like globbing for property names, and emits the matched values separated by newlines.

    Examples:

    Let's start with a real-world example.

    Let's grab the even tweets from the last 10 pulled from Twitter's JSON feed http://apiwiki.twitter.com/Twitter-REST-API-Method:-statuses-public_timeline

    $ curl -s 'http://twitter.com/statuses/public_timeline.json' | jsongrep '[02468].text'
    ARGHHHHHH. facebook is being gay
    5-5 in the darts between Barney and Whitlock. Amazing. #darts
    I wonder if I'm still located on 5th ave?
    Estou de volta a internet .... Essa chuva n para ! Estou de boa com a minha familia .


    Yeah, that's just about what I expected.

    Now suppose you have a JSON document like the one in tests/ongz.json which looks like this:

    {
     "bah" : {
     "feh" : true,
     "foo" : 3,
     "lah" : "songz"
     },
     "blah" : {
     "lol" : "gongz"
     },
     "arr" : [
     "a", "b", "c", "d", "e",
     "f", "g", "h", "i", "j",
     "k", "l", "m", "n", "o",
     "p", "q", "r", "s", "t",
     "u", "v", "w", "x", "y",
     "z"
     ]
    }


    jsongrep will let you match structural patterns, where . (dot) separates nested properties.

    Let's glob on property names:

    $ jsongrep 'b*.l*' tests/ongz.json
    gongz
    songz


    Works on arrays, too:

    $ jsongrep 'arr.?' tests/ongz.json
    a
    b
    c
    d
    e
    f
    g
    h
    i
    j

    Note that we're still globbing, even though arrays have numeric indices:

    $ jsongrep 'arr.2?' tests/ongz.json
    u
    v
    w
    x
    y
    z


    If you specify a JSON subtree, that's what you get back:

    $ jsongrep 'bah' tests/ongz.json
    {"foo": 3, "lah": "songz", "feh": true}


    Syntax

    jsongrep currently supports normal shell glob patterns within property names:

    ? Matches any one character
    * Matches any number of characters within a field
    [seq] Matches any of the characters in seq
    [!seq] Matches any of the characters not in seq


    Dot is the field separator.

    Usage

    Usage: jsongrep [options] [PATTERN | -e PATTERN [-e PATTERN ...]] [FILE]

    Parses JSON data structurally to select a subset of data.

    Options:
     --version show program's version number and exit
     -h, --help show this help message and exit
     -e PATTERNS, --pattern=PATTERNS
     Additional patterns to match.
     -D, --detect-encoding
     Attempts to detect the character encoding of input if
     LC_TYPE and file.encoding provide insufficient hints.
     (Slow) [default: False]



    Product's homepage

    Requirements:

    · Python

      


    TAGS:

    JSON document | search bits | select bits | JSON | document | search

    Go to top

    WindowsGamesDriversMacLinuxScriptsMobileHandheldNews

    SUBMIT PROGRAM   |   ADVERTISE   |   GET HELP   |   SEND US FEEDBACK   |   RSS FEEDS   |   UPDATE YOUR SOFTWARE   |   ROMANIAN FORUM