GitHub - iaseth/josn: josn is a command-line JSON viewer.
source link: https://github.com/iaseth/josn
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
josn-cli
is a command-line JSON
viewer, written in JavaScript
and TypeScript
.
I felt the need for a JSON browser when I was working on iaseth/top-100-yc-companies
.
I primarily use it to verify the JSON data collected in my web scraping projects.
I have created a similar tool (jsonplus
) in C++
.
I am using readmix
for generating this README.
You can view the source file here.
Table of contents
Installation
You can install josn-cli
with the following command:
npm i -g josn-cli
Now you should be able to run the josn
command in your terminal.
Usage
-
Printing whole files
Provide the
filepath
as the first argument.- This will print the whole file as indented JSON:
josn filename.json
- When you supply a
path
that is a directory,josn
will automatically select thepackage.json
inside that directory:This is equivalent to writing:josn reactapp
josn reactapp/package.json
- When you supply a
path
that is a directory but it does not contain apackage.json
,josn
will try to find ajson
file in that directory:josn mydata/
- This will print the whole file as indented JSON:
-
Printing an object
You can use the
keyName
to traverse inside an object.- This will print the
dependencies
object insidepackage.json
:josn package.json dependencies
josn
is case insensitive, so you might as well write this:josn package.json Dependencies
- Or even this:
josn package.json DEPENDENCIES
- And you can skip parts of the key name if it is unique enough:
This will print the first
josn package.json dep
key
that starts with the prefixdep
. - You can use a
colonArg
for selecting just thekeys
orvalues
in an object:josn package.json dependencies :keys
Both,josn package.json dependencies :values
:keys
and:values
have a shorthand syntax:josn package.json dependencies :k
josn package.json dependencies :v
- This will print the
-
Printing an array element
You can use numbers to select array elements.
- This will print the first element of the data array:
josn data.json data 0
- You can also use negative indices to select an element from the end:
This will print last element of
josn data.json data -1
data
array. - You can use a
colonArg
for selecting just theeven
orodd
elements in an Array:josn data.json data :even
Keep in mind that array indexes start at 0, sojosn data.json data :odd
:even
will select elements at0, 2, 4, etc
and vice-versa. - You can use a
colonArg
for slicing an Array:josn data.json data :10 // select first 10 elements
josn data.json data -10: // select last 10 elements
The slice syntax is heavily inspired by its counterpart injosn data.json data 2:5 // select elements from 2 to 4
Python
.
- This will print the first element of the data array:
Package details
Name |
Value |
---|---|
Name |
josn-cli |
Description |
JOSN is a command line JSON viewer. |
Version |
0.8.13 |
Author |
iaseth |
Homepage |
https://github.com/iaseth/josn |
Repository |
iaseth/josn |
License |
MIT |
Dependencies
Package |
Version |
|
---|---|---|
1 | json5 |
^2.2.3 |
2 | whichtype |
^0.9.0 |
Dev dependencies
Package |
Version |
|
---|---|---|
1 | @types/jest |
^29.5.1 |
2 | jest |
^29.5.0 |
License
MIT License
Copyright (c) Ankur Seth.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Credit
This file was generated using readmix
.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK