Skip to content

dporru/json_manipulate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JSON Manipulate

Manipulate JSON strings from the command line.

Installation

Install using pip:

$ pip install json_manipulate

Usage

Call the json_manipulate.py with a json-string as standard input and a manipulation string. For example:

$ json_string='{"first_name" : "Henk", "last_name" : "de Wit", "birth_date" : "1969-03-12"}'
$ echo $json_string | json_manipulate.py -m 'first_name'
{
    "first_name": "Henk"
}

If you ommit the -m flag, you just get the json-string nicely readable on your screen.

More examples

Select subkeys:

$ json_string='{"person" : {"first_name" : "Henk", "last_name" : "de Wit", "birth_date" : "1969-03-12"}}'
$ echo $json_string | json_manipulate.py -m 'person.first_name'
{
    "person": {
        "first_name": "Henk"
    }
}

Select multiple keys:

$ json_string='{"person" : {"first_name" : "Henk", "last_name" : "de Wit", "birth_date" : "1969-03-12"}}'
$ echo $json_string | json_manipulate.py -m 'person.(first_name|last_name)'
{
    "person": {
        "first_name": "Henk",
        "last_name": "de Wit"
    }
}

Select keys from objects inside a list:

$ json_string='{"persons" : [{"first_name" : "Henk", "last_name" : "de Wit", "birth_date" : "1969-03-12"}, {"first_name" : "Karin", "last_name" : "de Wit", "birth_date" : "1970-11-05"}]}'
$ echo $json_string | json_manipulate.py -m 'persons[first_name|last_name]'
{
    "persons": [
        {
            "first_name": "Henk",
            "last_name": "de Wit"
        },
        {
            "first_name": "Karin",
            "last_name": "de Wit"
        }
    ]
}

About

Manipulate JSON strings from the command line

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages