feat(serialize): overload table to render json on cmd end#1
Open
feat(serialize): overload table to render json on cmd end#1
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why this should be merged
The addition of a
RenderJSONmethod to thetable.Writerenables native JSON rendering without requiring external transformations or custom code. This simplifies workflows for JSON-based applications. It enhances the flexibility ofgo-prettywhile maintaining the existing rendering capabilities.How this works
A new
PrintIfJsonmethod is added to thetable.Writer. It formats the table data (headers and rows) into structured JSON at the end of the command.Flat table example:
As table:
As json:
{ "ash_validators": [ { "node_id": "NodeID-ECKiPtNQJrDYoGKma2yKaKzvuJT7V4HCz", "remaining_balance": "0.1", "validation_id": "bV23Ev9wL4pGYgfqVk88awYfshkGzfdgQ3w12h1hurX2r2hBR", "weight": "100" } ] }Grouped data example:
As table:
As json:
{ "ash": { "local_network": { "blockchainid_cb58": "fj65yEMzzb91Lo3EBawiHRqevQv2zoYGrH8CuopydnLGfFH56", "blockchainid_hex": "0x57ee6b52e3d3c948aca98e1ce4440e143bfacc7f8c1628a27b740423fd6ca12a", "chainid": "7777", "rpc_endpoint": "http://127.0.0.1:43287/ext/bc/fj65yEMzzb91Lo3EBawiHRqevQv2zoYGrH8CuopydnLGfFH56/rpc", "subnetid": "GEieSy2doZ96bpMo5CuHPaX1LvaxpKZ9C72L22j94t6YyUb6X" }, "name": "ash", "validation": "Proof Of Authority", "vm_id": "jvFW8PbuerjWravW4Gbfe8W1GsVSQNPrLncseZG8vTX5nwqWh", "vm_version": "v0.7.0" } }How this was tested
jqto validate the format.How is this documented
How to test it (impacted command)
Run the following commands to validate JSON rendering integration:
Related feature request