Sample Header Ad - 728x90

How to do formatted printing with jq?

32 votes
3 answers
82935 views
jq has built-in ability to convert numbers to string or concatenate strings. How can I format strings inside jq similar to printf like padding (%4s). For example, how can I force number to occupy 10 char spaces with left alignment? echo '{"title" : "A sample name", "number" : 1214}' | jq '(.title) + " " + (.number | tostring)'
Asked by Zeta.Investigator (1190 rep)
Jul 20, 2021, 07:10 PM
Last activity: Jun 7, 2024, 06:30 AM