Cardano-node: [FR] - cardano-cli shelley query utxo should return json

Created on 25 Jul 2020  路  6Comments  路  Source: input-output-hk/cardano-node

Exernal

Describe the feature you'd like
I'm currently using Regex matching to retrieve the individual data bits out of this command:

$ cardano-cli shelley query utxo --address $(cat bcsh_owner.payment.addr) --cardano-mode --testnet-magic 42    
                           TxHash                                 TxIx        Lovelace
----------------------------------------------------------------------------------------
"0832f891bdceb8b925e73799e911ac612e2ff8782d1e19254deac12b297aeac9"     0      15670

I would prefer if the result could be returned as json for easier parsing instead of resorting to Regex. This will also make it easier for those doing scripting as they can just use jq to parse it instead of awk or whatever else they are currently using.

[
  {
    "txHash": "0832f891bdceb8b925e73799e911ac612e2ff8782d1e19254deac12b297aeac9",
    "txIx": 0,
    "lovelace": 15670
  }
]

Describe alternatives you've considered
Just doing Regex.

enhancement

Most helpful comment

Something like

--output-format json

like we had in the ITN days would be ideal. We can always redirect the output to a file if we need to on our own.

All 6 comments

Just a note that Regex matching can be very fragile and my parsing broke from 1.16.x -> 1.17.x when you added double quotes around the TxHash.

If you use the --out-file option of the cardano-cli shelley query utxo command, it'll write out the JSON-encoded data. Do you think we should also just write it to stdout as JSON? Or allow the option to pick between formats? I'm not sure how useful this table format is.

The tx hash with double quotes problem was fixed here: https://github.com/input-output-hk/cardano-node/pull/1535. Shouldn't happen again.

Something like

--output-format json

like we had in the ITN days would be ideal. We can always redirect the output to a file if we need to on our own.

My scripts also broke from 1.16.x to 1.17.x due to the added double quotes. Should really be given as json output with a flag like Andrew gave about. Could also be --output json or -o like in kubectl.

@AndrewWestberg are you satisfied with how it is, with json output for files and text output for the stdout, or do you really want it to be orthogonal options?

This isn't going to be a high priority :smile:. You may find it's quicker to file a PR yourself implementing this.

Closing. Not a high priority for me either anymore.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cardanians picture cardanians  路  6Comments

aftershowrc picture aftershowrc  路  3Comments

Mercurial picture Mercurial  路  3Comments

2072 picture 2072  路  8Comments

dmitrystas picture dmitrystas  路  6Comments