Vector size in a JSON in Shell Script

0

I'd like to get the size of a vector in a JSON in the scriipt shell but I'm only getting the size of each vector string, ie for the example:

#!/bin/bash

j='{"Nomes": { "nome": ["maria", "jose", "vitor","caio"] }}'

echo $j
echo  $j | jq -r ".Nomes | .nome[] | length"

Exit beyond JSON:

5
4
5
4

But I wanted to get 4 that is the amount of items in the vector.

    
asked by anonymous 07.09.2018 / 22:17

1 answer

0

Try to remove [] :

echo  $j | jq -r ".Nomes.nome | length"
    
09.09.2018 / 21:05