Skip to main content

A command line tool to manipulate JSON files.

Project description

jsonwiz

🗷 A command line utility for manipulating JSON files

PyPI version Downloads Package Status

Overview

jsonwiz is a command-line tool for working with JSON files. You can retrieve, modify, add or delete any value in the JSON file, then save the changes back to disk. To access a specific property deep in the tree, you can navigate nested objects and arrays using the dot (.) or slash (/) syntax.

Installation

jsonwiz can be installed via pip through PyPi

pip install jsonwiz

Usage

Once jsonwiz is installed, you can use the following command to interact with the cli

jsonwiz COMMAND [FILE] [PATH] [VALUE] [--ARGS]
COMMAND Command to run
FILE Path to JSON file
PATH Key name or path (dot notation or slash notation)
VALUE The new value for `set` command
ARGS Optional arguments to pass. Check below

Example

jsonwiz set example.json person.name "John" --type string

This would write a name key into the person object, and set the value to John as a string

  "person": {
    "name": "John"
  }

Commands

get

The get command fetches an existing value, and outputs it to the console.

jsonwiz get example.json person.name

set

The set command will create or replace a key. If the key exists, it will override the exisiting value. It also automatically creates any parent objects if necessary.

jsonwiz set example.json person.age 32 --type string 

The data type of the new value is guessed by the format. To assert required data type, pass the --type argument. Read about it here.

delete

The delete command will delete an existing key, and fail if the key or any parent objects don't exist.

jsonwiz delete example.json person.age

validate

The validate command simply checks if the input JSON is valid or not.

jsonwiz validate example.json

Arguments

--type

The --type is an optional argument to specify the data type of the new value. To be used with the set command.

Supported types are - string, integer, float, boolean, null and object

Example: Pass a boolean value

jsonwiz set example.json person.subscribed true --type boolean

Output:

{
  "person": {
    "name": "John",
    "subscribed": true
  }
}

Pass JSON values

It is possible to add entire JSON fragments to your file by replacing an existing object/creating a new object. Recommended to use --type object to correctly parse your value as JSON when applying to the document. Make sure to properly escape your quotes when attempting this.

jsonwiz set example.json person.address '{\"city\":\"Mumbai\"}' --type object

Output:

  "person": {
    "address": {
      "city": "Mumbai"
    }
  }

Pass Arrays

You can traverse arrays just like any other object, simply by specifying the array index as the key. Make sure to use --type object for array insertions to work properly. Make sure to properly escape your quotes when attempting this.

Sample JSON
{
"person": {
  "address": {
    "city": "Mumbai"
  },
  "items": [
    {
      "name": "item1"
    },
    {
      "name": "item2"
    }
  ]
}
}

get

jsonwiz get example.json person.items.0.name

set

  1. Create empty array
jsonwiz get example.json person.jobs [] --type object
  1. Create arrays with no strings
jsonwiz get example.json person.jobs [1,2,3] --type object
  1. Create arrays with string values
jsonwiz my_list '[\"value1\", \"value2\", \"value3\"]' --type object

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jsonwiz-0.0.1.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

jsonwiz-0.0.1-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file jsonwiz-0.0.1.tar.gz.

File metadata

  • Download URL: jsonwiz-0.0.1.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.0

File hashes

Hashes for jsonwiz-0.0.1.tar.gz
Algorithm Hash digest
SHA256 ca2931de8d0f3234cd435c856ecd51f1cdcacfd58e54479cdd3dd3feebddbf18
MD5 7946d6895d218182a6b94553662db208
BLAKE2b-256 6071cc84e23985ae93ea16184df3f1b983278f0e76329c92e0322fede57f36e6

See more details on using hashes here.

File details

Details for the file jsonwiz-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: jsonwiz-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.0

File hashes

Hashes for jsonwiz-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 45da18f2dc79b4bf71dfb58bc88ed8b407b744d68b0831a20dbcaf2be8c503b4
MD5 75c8be3d568a18aeb89926cb0b78e9a8
BLAKE2b-256 e7b18c639be1ae6734291c4fa53bda262dcbbbe8da78857c632ae61ddf679364

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page