Skip to main content
Commonmark migration
Source Link

You could delete arrays first, e.g.:

del(.[] | select(type=="array"))

To only keep objects do something like this:

<infile.json jq -r '
del(.[] | select(type!="object")) |
paths                             |
map(tostring)                     |
select(length==2)                 |
join(".")
'

Output:

coord.lon
coord.lat
main.temp
main.pressure
main.humidity
main.temp_min
main.temp_max
wind.speed
wind.deg
rain.1h
clouds.all
sys.type
sys.id
sys.country
sys.sunrise
sys.sunset

Edit

##Edit PerhapsPerhaps you want a combination of the two answers?

paths(scalars)      |
select(length >= 2) |
map(tostring)       |
join(".")

Output:

coord.lon
coord.lat
weather.0.id
weather.0.main
weather.0.description
weather.0.icon
main.temp
main.pressure
main.humidity
main.temp_min
main.temp_max
wind.speed
wind.deg
rain.1h
clouds.all
sys.type
sys.id
sys.country
sys.sunrise
sys.sunset

You could delete arrays first, e.g.:

del(.[] | select(type=="array"))

To only keep objects do something like this:

<infile.json jq -r '
del(.[] | select(type!="object")) |
paths                             |
map(tostring)                     |
select(length==2)                 |
join(".")
'

Output:

coord.lon
coord.lat
main.temp
main.pressure
main.humidity
main.temp_min
main.temp_max
wind.speed
wind.deg
rain.1h
clouds.all
sys.type
sys.id
sys.country
sys.sunrise
sys.sunset

##Edit Perhaps you want a combination of the two answers?

paths(scalars)      |
select(length >= 2) |
map(tostring)       |
join(".")

Output:

coord.lon
coord.lat
weather.0.id
weather.0.main
weather.0.description
weather.0.icon
main.temp
main.pressure
main.humidity
main.temp_min
main.temp_max
wind.speed
wind.deg
rain.1h
clouds.all
sys.type
sys.id
sys.country
sys.sunrise
sys.sunset

You could delete arrays first, e.g.:

del(.[] | select(type=="array"))

To only keep objects do something like this:

<infile.json jq -r '
del(.[] | select(type!="object")) |
paths                             |
map(tostring)                     |
select(length==2)                 |
join(".")
'

Output:

coord.lon
coord.lat
main.temp
main.pressure
main.humidity
main.temp_min
main.temp_max
wind.speed
wind.deg
rain.1h
clouds.all
sys.type
sys.id
sys.country
sys.sunrise
sys.sunset

Edit

Perhaps you want a combination of the two answers?

paths(scalars)      |
select(length >= 2) |
map(tostring)       |
join(".")

Output:

coord.lon
coord.lat
weather.0.id
weather.0.main
weather.0.description
weather.0.icon
main.temp
main.pressure
main.humidity
main.temp_min
main.temp_max
wind.speed
wind.deg
rain.1h
clouds.all
sys.type
sys.id
sys.country
sys.sunrise
sys.sunset
Guessing what the OP wants
Source Link
Thor
  • 17.5k
  • 3
  • 55
  • 71

You could delete arrays first, e.g.:

del(.[] | select(type=="array"))

To only keep objects do something like this:

<infile.json jq -r '
del(.[] | select(type!="object")) |
paths                             |
map(tostring)                     |
select(length==2)                 |
join(".")
'

Output:

coord.lon
coord.lat
main.temp
main.pressure
main.humidity
main.temp_min
main.temp_max
wind.speed
wind.deg
rain.1h
clouds.all
sys.type
sys.id
sys.country
sys.sunrise
sys.sunset

##Edit Perhaps you want a combination of the two answers?

paths(scalars)      |
select(length >= 2) |
map(tostring)       |
join(".")

Output:

coord.lon
coord.lat
weather.0.id
weather.0.main
weather.0.description
weather.0.icon
main.temp
main.pressure
main.humidity
main.temp_min
main.temp_max
wind.speed
wind.deg
rain.1h
clouds.all
sys.type
sys.id
sys.country
sys.sunrise
sys.sunset

You could delete arrays first, e.g.:

del(.[] | select(type=="array"))

To only keep objects do something like this:

<infile.json jq -r '
del(.[] | select(type!="object")) |
paths                             |
map(tostring)                     |
select(length==2)                 |
join(".")
'

Output:

coord.lon
coord.lat
main.temp
main.pressure
main.humidity
main.temp_min
main.temp_max
wind.speed
wind.deg
rain.1h
clouds.all
sys.type
sys.id
sys.country
sys.sunrise
sys.sunset

You could delete arrays first, e.g.:

del(.[] | select(type=="array"))

To only keep objects do something like this:

<infile.json jq -r '
del(.[] | select(type!="object")) |
paths                             |
map(tostring)                     |
select(length==2)                 |
join(".")
'

Output:

coord.lon
coord.lat
main.temp
main.pressure
main.humidity
main.temp_min
main.temp_max
wind.speed
wind.deg
rain.1h
clouds.all
sys.type
sys.id
sys.country
sys.sunrise
sys.sunset

##Edit Perhaps you want a combination of the two answers?

paths(scalars)      |
select(length >= 2) |
map(tostring)       |
join(".")

Output:

coord.lon
coord.lat
weather.0.id
weather.0.main
weather.0.description
weather.0.icon
main.temp
main.pressure
main.humidity
main.temp_min
main.temp_max
wind.speed
wind.deg
rain.1h
clouds.all
sys.type
sys.id
sys.country
sys.sunrise
sys.sunset
added 463 characters in body
Source Link
Thor
  • 17.5k
  • 3
  • 55
  • 71

You could delete arrays first, e.g.:

del(.[] | select(type=="array"))

To only keep objects do something like this:

<infile.json jq -r '
del(.[] | select(type!="object")) |
paths                             |
map(tostring)                     |
select(length==2)                 |
join(".")
'

Output:

coord.lon
coord.lat
main.temp
main.pressure
main.humidity
main.temp_min
main.temp_max
wind.speed
wind.deg
rain.1h
clouds.all
sys.type
sys.id
sys.country
sys.sunrise
sys.sunset

You could delete arrays first, e.g.:

del(.[] | select(type=="array"))

You could delete arrays first, e.g.:

del(.[] | select(type=="array"))

To only keep objects do something like this:

<infile.json jq -r '
del(.[] | select(type!="object")) |
paths                             |
map(tostring)                     |
select(length==2)                 |
join(".")
'

Output:

coord.lon
coord.lat
main.temp
main.pressure
main.humidity
main.temp_min
main.temp_max
wind.speed
wind.deg
rain.1h
clouds.all
sys.type
sys.id
sys.country
sys.sunrise
sys.sunset
Source Link
Thor
  • 17.5k
  • 3
  • 55
  • 71
Loading