flo-l / jsonpp-rs Goto Github PK
View Code? Open in Web Editor NEWUNIX style tool to pretty print json
License: GNU General Public License v3.0
UNIX style tool to pretty print json
License: GNU General Public License v3.0
Hi.
Consider the following test:
[user@host ~]$ curl -s http://localhost:8080/fiscalidade/v1/version | jsonpp
{
"status": "ok",
"result": {
"major": 0,
"minor": 6,
"patch": 2
}
}[user@host ~]$
Notice the output JSON doesn't contains an end empty line. With this new feature, it would allow to print as:
[user@host ~]$ curl -s http://localhost:8080/fiscalidade/v1/version | jsonpp <some-option-here>
{
"status": "ok",
"result": {
"major": 0,
"minor": 6,
"patch": 2
}
}
[user@host ~]$
The cURL tool contains a -w
feature that is possible to do something like this:
[user@host ~]$ curl -s -w '\n' http://localhost:8080/fiscalidade/v1/version
{"status":"ok","result":{"major":0,"minor":6,"patch":2}}
[user@host ~]$
so, a good option to jsonpp
tool could be:
[user@host ~]$ curl -s http://localhost:8080/fiscalidade/v1/version | jsonpp -w '\n'
{
"status": "ok",
"result": {
"major": 0,
"minor": 6,
"patch": 2
}
}
[user@host ~]$
WDYT?
See jq.
While technically not a valid json file, I've come across many files where each line is a separate valid json object. jq
is an example of a command line tool that handles this gracefully by parsing and processing each line in turn. It would be nice if pp_rs handled these types of files
It would be cool to have an option for the formatter to print the comma at the beginning of the line. So instead of
{
"key1": "value1",
"key2": "value2"
}
it should print
{
"key1": "value1"
, "key2": "value2"
}
This would help when the file is version controlled because adding a new value in the first case would cause a 2 line diff while adding a value in the second case, would only cause a single line diff:
{
"key1": "value1",
"key2": "value2",
"key3": "value3"
}
vs.
{
"key1": "value1"
, "key2": "value2"
, "key3": "value3"
}
This is inspired by the format elm decided to use. Actually for better formatting, having the opening bracet and the first key/value pair in the same line would be nice to:
{ "key1": "value1"
, "key2": "value2"
}
You could implement a format optimized for version controll while still be human readable
As Rust is so strong performance-wise it'd be cool to be among the fastest json pretty printers out there.
Maybe as a start three files with ~1Kb, ~1MB and ~1GB..
I'd accept a PR anytime!
This would be immensely useful for piping (curl https://...json | pp
)
Json syntax highlighting would be a great addition to the library. One possibility is highlighting by default when stdout is a tty and no highlighting when stdout is a pipe or file. A --color
flag could be used to override default behavior
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.