How do I use jq to convert number to string?

后端 未结 4 1083
孤街浪徒
孤街浪徒 2020-12-29 01:56

Given the following jq command and Json:

jq \'.[]|[.string,.number]|join(\": \")\' <<< \'
[
  {
    \"number\": 3,
    \"string\": \"threee\"
  },
          


        
4条回答
  •  别那么骄傲
    2020-12-29 02:23

    The jq command has the tostring function. It took me a while to learn to use it by trial and error. Here is how to use it:

    jq -r '.[] | [ .string, .number|tostring ] | join(": ")' <<< '
    [{ "number": 9, "string": "nine"},
     { "number": 4, "string": "four"}]
    '
    nine: 9
    four: 4
    

提交回复
热议问题