title: Converting tsv with arrays to JSON with jq
body: <p>i found <a href="https://stedolan.github.io/jq/tutorial/" rel="nofollow noreferrer">jq</a> very helpful in converting tsv to JSON file, however, i want to figure out how to do it with jq when i have array in my tsv:</p>
  
  <pre><code>name    age    pets
  Tim    15    cats,dogs
  Joe    11    rabbits,birds
  ...
  </code></pre>
  
  <p>ideal JSON:</p>
  
  <pre><code>[
   {
    name: "Tim",
    age: "15",
    pet:["cats","dogs"]
   },
    name: "Joe",
    age: "11",
    pet:["rabbits","birds"]
   }, ...
  ]
  </code></pre>
  
  <p>This is the command i tried:</p>
  
  <pre><code>cat file.tsv | jq -s  --slurp --raw-input --raw-output 'split("\n") | .[1:-1] | map(split("\t")) |
          map({"name": .[0],
               "age": .[1],
               "pet": .[2]})'
  </code></pre>
  
  <p>and the output the the above command is:</p>
  
  <pre><code>[
   {
    name: "Tim",
    age: "15",
    pet:"cats,dogs"
   },
    name: "Joe",
    age: "11",
    pet:"rabbits,birds"-
   }, ...
  ]
  </code></pre>