Git Product home page Git Product logo

jsonpp's Introduction

jsonpp

A command line JSON pretty printer.

Pretty print web service responses like so:

curl -s -L http://t.co/tYTq5Pu | jsonpp

and make beautiful the files running around on your disk:

jsonpp testdata/multiple/multiple.json

You can also format previously pretty-printed code with "-s":

jsonpp -s testdata/one/singular.json

Jsonpp exists because a friend was building against an API with large JSON APIs and was tired of the noticable wait times that other languages' tooling had. Then, jsonpp turned out to be pretty nice for parsing the JSON log files we had lying around and I made it a thing.

Install

Installable with go get github.com/jmhodges/jsonpp, brew install jsonpp, or copying the binary to your $PATH. See the live documentation for details.

Options

The string used for indentation defaults to 2 spaces, but can be overridden by the environment variable JSONPP_INDENT.

Adding the "-s" parameter will allow you to format already formatted JSON code by assuming the entire input stream is one JSON object.

jsonpp's People

Contributors

bbbmmmlll avatar jmhodges avatar shoenig avatar tnm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jsonpp's Issues

Memory corruption backtrace

➜ json-schema-gen-v4 git:(ros-274-json-schema) ✗ jsonpp < target/schema.json > ~/schema.json
unexpected fault address 0x1af93683ff41
throw: fault

[signal 0xb code=0x1 addr=0x1af93683ff41 pc=0x9bf1]

runtime.throw+0x40 /Users/jhodges/projects/go/src/pkg/runtime/runtime.c:111
    runtime.throw(0xdda8e, 0x1af93683ff41)
runtime.sigpanic+0xe7 /Users/jhodges/projects/go/src/pkg/runtime/darwin/thread.c:473
    runtime.sigpanic()
runtime.MCentral_FreeList+0x30 /Users/jhodges/projects/go/src/pkg/runtime/mcentral.c:105
    runtime.MCentral_FreeList(0x20fafc8, 0x0, 0x1af93683ff41, 0xb44a, 0x20ff000, ...)
ReleaseN+0x99 /Users/jhodges/projects/go/src/pkg/runtime/mcache.c:76
    ReleaseN(0x20ff000, 0x20ff000, 0x0, 0xf83fffff00, 0xf8400110d8, ...)
runtime.MCache_ReleaseAll+0x53 /Users/jhodges/projects/go/src/pkg/runtime/mcache.c:130
    runtime.MCache_ReleaseAll(0x20ff000, 0x20a4)
stealcache+0x3a /Users/jhodges/projects/go/src/pkg/runtime/mgc0.c:528
    stealcache()
runtime.gc+0x1ca /Users/jhodges/projects/go/src/pkg/runtime/mgc0.c:617
    runtime.gc(0xf800000000, 0x100000)
runtime.mallocgc+0x1da /Users/jhodges/projects/go/src/pkg/runtime/malloc.c:79
    runtime.mallocgc(0x100000, 0x100000001, 0xf800000001, 0x1, 0x140010780, ...)
makeslice1+0x7d /Users/jhodges/projects/go/src/pkg/runtime/slice.c:46
    makeslice1(0x51a90, 0x10000000000000, 0x213ff38, 0x9324, 0x0, ...)
runtime.makeslice+0x86 /Users/jhodges/projects/go/src/pkg/runtime/slice.c:26
    runtime.makeslice(0x51a90, 0x0, 0x100000, 0xf840010780, 0x10000000000000, ...)
main.main+0xa4 /Users/jhodges/projects/jsonpp/jsonpp.go:18
    main.main()
runtime.mainstart+0xf /Users/jhodges/projects/go/src/pkg/runtime/amd64/asm.s:78
    runtime.mainstart()
runtime.goexit /Users/jhodges/projects/go/src/pkg/runtime/proc.c:246
    runtime.goexit()
----- goroutine created by -----
_rt0_amd64+0xc9 /Users/jhodges/projects/go/src/pkg/runtime/amd64/asm.s:65

Fails on already pretty JSON

This works:

{"id": 28345}

But this:

{
  "id": 28345
}

gives an error:

ERROR: Broken json on line 1: unexpected end of JSON input
  Context: {

"brew install jsoncpp" installs wrong architecture

Hi,
I'm on a Ubuntu 16.04 x86_64 architecture and when I do "brew install jsonpp" it installs the os x version :-/

what's the source of this problem and how to fix it ?

here's the details :

vincent@vincent-UX305UA:~/.linuxbrew/bin$ brew remove jsonpp
Uninstalling /home/vincent/.linuxbrew/Cellar/jsonpp/1.3.0... (5 files, 2MB)
vincent@vincent-UX305UA:~/.linuxbrew/bin$ linuxbrew install jsonpp
==> Downloading https://github.com/jmhodges/jsonpp/releases/download/1.3.0/jsonpp-1.3.0-osx-x86_64.zip
Already downloaded: /home/vincent/.cache/Homebrew/jsonpp-1.3.0.zip
🍺  /home/vincent/.linuxbrew/Cellar/jsonpp/1.3.0: 5 files, 2MB, built in 0 seconds
vincent@vincent-UX305UA:~/.linuxbrew/bin$ ll /home/vincent/.linuxbrew/Cellar/jsonpp/1.3.0
total 28
drwxrwxr-x 4 vincent vincent 4096 sep  4 08:46 ./
drwxrwxr-x 3 vincent vincent 4096 sep  4 08:46 ../
drwxrwxr-x 2 vincent vincent 4096 sep  4 08:46 bin/
drwxrwxr-x 2 vincent vincent 4096 sep  4 08:46 .brew/
-rw-rw-r-- 1 vincent vincent  583 sep  4 08:46 INSTALL_RECEIPT.json
-rw-r--r-- 1 vincent vincent 1055 mai  1  2016 LICENSE
-rw-r--r-- 1 vincent vincent 1115 oct 13  2016 README.md
vincent@vincent-UX305UA:~/.linuxbrew/bin$ ll /home/vincent/.linuxbrew/Cellar/jsonpp/1.3.0/bin
total 2136
drwxrwxr-x 2 vincent vincent    4096 sep  4 08:46 ./
drwxrwxr-x 4 vincent vincent    4096 sep  4 08:46 ../
-r--r--r-- 1 vincent vincent 2177168 oct 13  2016 jsonpp
vincent@vincent-UX305UA:~/.linuxbrew/bin$ chmod ugo+x /home/vincent/.linuxbrew/Cellar/jsonpp/1.3.0/bin/jsonpp 
vincent@vincent-UX305UA:~/.linuxbrew/bin$ ll /home/vincent/.linuxbrew/Cellar/jsonpp/1.3.0/bin/jsonpp 
-r-xr-xr-x 1 vincent vincent 2177168 oct 13  2016 /home/vincent/.linuxbrew/Cellar/jsonpp/1.3.0/bin/jsonpp*
vincent@vincent-UX305UA:~/.linuxbrew/bin$  /home/vincent/.linuxbrew/Cellar/jsonpp/1.3.0/bin/jsonpp 
bash: /home/vincent/.linuxbrew/Cellar/jsonpp/1.3.0/bin/jsonpp: cannot execute binary file: Exec format error
vincent@vincent-UX305UA:~/.linuxbrew/bin$ 

Reformat file with replacement

It would be handy to reformat (pretty print) a file 'into itself', i.e. reformat it.
So instead of several commands like

jsonpp data.json > data-tmp.json
rename data-tmp.json data.json
delete data-tmp.json

I would need only one command like jsonpp -f data.json.

enums over and over

Is there any way to get Java enums to turn into some sort of top-level item? I get the same long enumeration over and over in the schema.

"script": {
          "type": "string",
          "enum": [
            "Dsrt",
            "Bamu",
            ...
            }

There are many items in the list, and it turns up in my schema many times.

The order is also rather randomized, FWIW.

sorting dictionary keys by name

Thank you for your nice tool!

It would be easier to read the output if dictionary keys were sorted by name.
Like, for {"bb":{}, "aa": 1, "cc": null} instead of

{
  "bb": {},
  "aa": 1,
  "cc": null
}

the output would be

{
  "aa": 1,
  "bb": {},
  "cc": null
}

upx released jsonpp binary results Segmentation fault (core dumped)

i tried to upx --best to your released pre-compiled linux binary, then run jsonpp and error occurred:

Segmentation fault (core dumped)

but i go build -ldflags="-s -w" jsonpp myself and then upx --best, everything is ok

go version: go1.8 linux/amd64
os:

lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.2 LTS
Release: 16.04
Codename: xenial

upx version:

upx --version
upx 3.91
UCL data compression library 1.03
LZMA SDK version 9.22 beta
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2013 Laszlo Molnar
Copyright (C) 2000-2013 John F. Reiser
Copyright (C) 2002-2013 Jens Medoch
Copyright (C) 1999-2006 Igor Pavlov
UPX comes with ABSOLUTELY NO WARRANTY; for details type 'upx -L'.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.