Skip to main content

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

Metadata

Release files for jsonwiz 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jsonwiz 0.0.1
File Size Uploaded
jsonwiz-0.0.1.tar.gz 5.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for jsonwiz 0.0.1
File Interpreter ABI Platform
jsonwiz-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 10.8 kB

Release files / jsonwiz-0.0.1.tar.gz

Download URL jsonwiz-0.0.1.tar.gz
Size 5.3 kB
Tags Source
SHA-256 checksum
How to use checksums
ca2931de8d0f3234cd435c856ecd51f1cdcacfd58e54479cdd3dd3feebddbf18
BLAKE2b-256 checksum
How to use checksums
6071cc84e23985ae93ea16184df3f1b983278f0e76329c92e0322fede57f36e6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.0

Release files / jsonwiz-0.0.1-py3-none-any.whl

Download URL jsonwiz-0.0.1-py3-none-any.whl
Size 5.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
45da18f2dc79b4bf71dfb58bc88ed8b407b744d68b0831a20dbcaf2be8c503b4
BLAKE2b-256 checksum
How to use checksums
e7b18c639be1ae6734291c4fa53bda262dcbbbe8da78857c632ae61ddf679364
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.0

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page