PaulJuliusMartinez / jless

jless is a command-line JSON viewer designed for reading, exploring, and searching through JSON data.
https://jless.io
MIT License
4.73k stars 91 forks source link

Add x/u/U commands to hide/unhide/unhide-all nodes #146

Open YongJieYongJie opened 8 months ago

YongJieYongJie commented 8 months ago

Proposed Feature: Ability to hide and unhide nodes

One of jless's major strength over simple pretty-printing of JSON is the interactivity it provides. This PR adds support for hiding and unhiding of individual map key nodes (based on jq query matching), enhancing the interactivity by allowing user to hide irrelevant nodes to better navigate and view the JSON.

The attached video demonstrates three features:

  1. Using x to hide individual object keys (ServiceId, ServiceType and AvailabilityZones). Notice that the objects keys are hidden across all objects in the ServiceDetails array.
  2. Using u to undo hiding of the above object keys one at a time
  3. Using U to undo hiding of all object keys all at once

https://github.com/PaulJuliusMartinez/jless/assets/14101781/bdf0911d-f905-4a46-83d0-ee88402a579b

Changes

  1. Additional vec<string> field on the flatjson struct to store jq paths for testing which rows to hide.
    • When x is pressed, we generate the jq path for the current node, and push it to the above vector.
    • When u is pressed, we pop the last item of the above vector.
    • When U is pressed, we clear the vector.
  2. Update implementation of flatjson::next_visible_row() and flatjson::prev_visible_row() to skip over hidden rows.
    • A row needs to be hidden if its jq path is included in the vector above.