Is there some CLI tool to format Candid responses like how jq does for JSON?

I’m referring to this

Also, I noticed something peculiar. Here’s a response of 10 vs 20 paginated items returned by an API for an app that we’re working on. The 10 items are automatically formatted, but the 20 aren’t. Wondering why.

10 items

20 items


1 Like

I just looked at the dfx source code and it appears that for dfx canister call you should be able to provide --output pp to pretty-print the output.

1 Like

You’re right. It’s documented here.

Soooo, it didn’t quite work. This is the output I’m seeing

Maybe I’m doing something wrong?

This is why:

1 Like

That seems like an arbitrary limitation.

Maybe we could raise/remove it? Or add another parameter that lets users specify that limit when making the call?

You could use GitHub - dfinity/idl2json to convert candid to json and then use jq.

As for the pretty printing, we stopped pretty printer when the data is too large, due to several reasons:

  1. it’s hard to know a good format for large data. For example, vec { 1;2;3 } .vs. vec {\n 1;\n2;\n3;\n };
  2. The pretty printer we used is unfortunately not linear time, so for large data, it’s not very efficient;
  3. Even with the same type, we may need different format for different cases. For example, both account_id and asset_content can be of type blob, but we may prefer to display account_id in hex, and asset_content as printable ascii. Ideally, we need a way to specify how to pretty print each field.

Ok. I’ll try to use idl2json for now. Thank you for the workaround.

P.S. I think it’s helpful to provide prebuilt binaries for idl2json. Figuring out another build toolchain is cumbersome and deters adoption :slight_smile:
Created an issue here


Hi @chenyan, may I ask a question?

From the terminal, I need to call a canister, wait for its response, and then use a part of that response to call another canister.

How would you recommend that I do that? Should I try to use this tool or could I do so with ic-repl?

Thanks in advance

Yep, you can use ic-repl. Here is one example: GitHub - chenyan2002/ic-repl for your use case.

1 Like