#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import print_function, unicode_literals

import argparse
import json
import sys

try:
    from pygments import highlight
    from pygments.lexers import get_lexer_by_name
    from pygments.formatters import get_formatter_by_name

    lexer = get_lexer_by_name('json')
    formatter = get_formatter_by_name('terminal256')

    def print_colorized(data, dst=sys.stdout):
        if hasattr(dst, 'isatty') and dst.isatty():
            print(highlight(data, lexer, formatter), end='', file=dst)
        else:
            print(data, file=dst)
except ImportError as e:
    def print_colorized(data, dst=sys.stdout):
        print(data, file=dst)


def build_filters(filter_definitions):
    filters = []

    if not filter_definitions:
        return lambda item: bool(item)

    for definition in filter_definitions:
        key, value = definition.split(':', 1)
        filters.append(lambda data: key in data and data[key] == value)

    def _filter(item):
        return item and all(flt(item) for flt in filters)

    return _filter


def json_loads(data):
    try:
        return json.loads(data)
    except ValueError:
        pass


p = argparse.ArgumentParser()
p.add_argument('-f', '--field', type=str)
p.add_argument('-g', '--grep', action='append')
# p.add_argument('-l', '--highlight', type=str)
args = p.parse_args()

filters = build_filters(args.grep)

data = map(json_loads, sys.stdin)
data = filter(filters, data)
data.sort(key=lambda item: item[args.field])

for line in data:
    line = json.dumps(line)
    print_colorized(line)

@@ -40,16 +40,255 @@
 -8 -*-%0A%0A
+%22%22%22 jsontool - Perform some actions with json using CLI%0A    http://github.com/mysz/jsontool%0A    Author: Marcin Sztolcman (marcin@urzenia.net)%0A%0A    Get help with: jsontool.py --help%0A    Information about version: jsontool.py --version%0A%22%22%22%0A%0A
 from __f
@@ -336,16 +336,39 @@
 terals%0A%0A
+__version__ = '0.1.0'%0A%0A
 import a
@@ -387,16 +387,31 @@
 rt json%0A
+import os.path%0A
 import s
@@ -977,16 +977,180 @@
 =dst)%0A%0A%0A
+def show_version():%0A    %22%22%22 Show version info and exit.%0A    %22%22%22%0A%0A    print('%7B0%7D: version %7B1%7D'.format(os.path.basename(sys.argv%5B0%5D), __version__))%0A    sys.exit(0)%0A%0A%0A
 def buil
@@ -1754,16 +1754,71 @@
 ppend')%0A
+p.add_argument('-v', '--version', action='store_true')%0A
 # p.add_
@@ -1880,16 +1880,53 @@
 args()%0A%0A
+if args.version:%0A    show_version()%0A%0A
 filters 

version info and other things preparing to put into pip