adamritter / fastgron

High-performance JSON to GRON (greppable, flattened JSON) converter
MIT License
592 stars 10 forks source link

Would like ability to suppress newlines separating similar paths #10

Closed chs-bnet closed 1 year ago

chs-bnet commented 1 year ago

When I upgraded to 0.5.0 I noticed that fastgron now separates what seems like similar or grouped json paths by inserting newlines. Personally, I would love for this to be disabled by default, but otherwise I'd appreciate a flag to disable this behavior.

I can run the output through awk 'NF' but then I lose the nice color output.

Thanks for considering this request.

adamritter commented 1 year ago

I think you are talking about not ending lines with semicolon... I added --semicolon switch (just use -h or --help to see the switches). Also you can force color with --color.

Regarding the defaults: I'm not sure what's the best default to tell you the truth :)

adamritter commented 1 year ago

Actually I'm not sure what you want to suppress, you are not talking about semicolons I think.

Can you write an example?

chs-bnet commented 1 year ago

Sure, here's an example from json I grabbed from data.gov:

json.meta.view.columns[10].cachedContents.largest = "DANGEROUS ANIMAL-FIREARM USED"
json.meta.view.columns[10].cachedContents.null = "0"    
json.meta.view.columns[10].cachedContents.top = []  
json.meta.view.columns[10].cachedContents.top[0] = {}
json.meta.view.columns[10].cachedContents.top[0].item = "DANGEROUS ANIMAL-FIREARM USED"
json.meta.view.columns[10].cachedContents.top[0].count = "1" 

json.meta.view.columns[10].cachedContents.smallest = "DANGEROUS ANIMAL-FIREARM USED"
json.meta.view.columns[10].cachedContents.count = "1"
json.meta.view.columns[10].cachedContents.cardinality = "1"

json.meta.view.columns[10].format = {}
json.meta.view.columns[11] = {}

json.meta.view.columns[11].cachedContents.top[0].item = "2021-09-01T00:00:00.000"
json.meta.view.columns[11].cachedContents.top[0].count = "1"

json.meta.view.columns[11].cachedContents.smallest = "2021-09-01T00:00:00.000"
json.meta.view.columns[11].cachedContents.count = "1"
json.meta.view.columns[11].cachedContents.cardinality = "1"

json.meta.view.columns[11].format = {}        
json.meta.view.columns[12] = {}                      
json.meta.view.columns[12].id = 558895162

json.meta.view.columns[12].cachedContents.top[0].count = "1"

json.meta.view.columns[12].cachedContents.smallest = "dog"
json.meta.view.columns[12].cachedContents.count = "1"
json.meta.view.columns[12].cachedContents.cardinality = "1"

json.meta.view.columns[12].format = {}            
json.meta.view.columns[13] = {}

json.meta.view.columns[13].cachedContents.top[0].count = "1"

json.meta.view.columns[13].cachedContents.count = "1"
json.meta.view.columns[13].cachedContents.cardinality = "1"

I didn't want the snipped to be too long so I cut out some lines, but as you can see there are a bunch of seemingly random newlines in the output.

[chs @ chs-vm] $> fastgron --version
fastgron version 0.5.0

I don't think it's a terminal column issue either:

[chs @ chs-vm] $> stty -a
speed 38400 baud; rows 90; columns 380; line = 0;

I'm running inside tmux 90% of the time, but I've verified this behavior outside of tmux as well.

Shell: Bash. OS: Linux. Distribution:

[chs @ chs-vm] $> cat /etc/lsb-release 
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=20.04
DISTRIB_CODENAME=focal
DISTRIB_DESCRIPTION="Ubuntu 20.04.6 LTS"

I've tried with and without the --semicolon and --no-indent flags but I get the same behavior

adamritter commented 1 year ago

Thanks Chris,

I fixed the bug and released 0.5.1, it was a bug in the speed optimization (now it's faster and bug free at the same time :) ).

The only problem is that homebrew release doesn't work, so you have to use either the GitHub release or build from source.

chs-bnet commented 1 year ago

Awesome! Thank you!