sgreben / jp

dead simple terminal plots from JSON data. single binary, no dependencies. linux, osx, windows.
MIT License
1.32k stars 33 forks source link

Make JSONPath results more consistent #15

Closed sgreben closed 5 years ago

sgreben commented 6 years ago

Background

Currently, our version of JSONPath has two index-selection behaviors:

Union-selection

The results are concatenated: first all 0-components, then all 1-components. This is the default behavior for field selection .[myField1, myField2] and was also chosen for index-selection for consistency.

All-selection

The results are interleaved: 0,1,0,1. This is the default JSONPath index selection behavior.

Proposal

Having both behaviors is confusing, all of these should have the same result.

Furthermore, it seems like echo '[[0,123],[1,456]]' | jp -xy '[*]', or echo '[[0,123],[1,456]]' | jp -xy '$', or even echo '[[0,123],[1,456]]' | jp should produce a valid plot:

 479.52│                     ▗
       │                  ▗▄▀▘
       │               ▄▄▀▘   
       │            ▄▞▀       
       │         ▄▞▀          
       │      ▄▞▀             
       │  ▗▄▀▀                
       │▄▀▘                   
 116.55└──────────────────────
       0                     1

Currently, only jp -xy '[*][0,1]' produces this.

I would propose that

  1. Results are always interleaved (i.e. [*][*] = [*][0,1] = 0.0, 0.1, 1.0, 1.1)
  2. An array of arrays is a valid result of the -xy JSONpath.
  3. The default behavior (no JSONPaths specified) is to assume [[x,y],[x,y],...] input.

Proposal 3. in particular is quite debatable, so I'd appreciate any feedback on this.

sgreben commented 6 years ago

This has been addressed in 1.1.9, but I'll keep the issue open in case someone has an opinion :)

sgreben commented 5 years ago

dead issue cleanup