1

I am trying to get all the date values in a json array for the dates inside the england-and-wales value.The array that like this (except it has a lot more values) the json array is here : https://www.gov.uk/bank-holidays.json

{"england-and-wales":{"division":"england-and-wales","events":[{"title":"New Year’s Day","date":"2015-01-01","notes":"","bunting":true}},{"title":"Good Friday","date":"2015-04-03","notes":"","bunting":false}]},"scotland":{"division":"scotla
nd","events":[{"title":"New Year’s Day","date":"2015-01-01","notes":"","bunting":true},{"title":"2nd January","date":"2015-01-02","notes":"","bunting":true},{"title":"Good Friday","date":"2
015-04-03","notes":"","bunting":false},{"title":"Early May bank holiday","date":"2015-05-04","notes":"","bunting":true}

As commented below the following will pick out all dates:

curl -s https://www.gov.uk/bank-holidays.json | jq '.. | .date? // empty'

Im not sure how to only pick dates inside the england-and-wales array?

jabra
  • 67
  • 7
  • 1
    Does this answer your question? [Recursive search values by key](https://stackoverflow.com/questions/38459429/recursive-search-values-by-key) – Inian Jul 22 '20 at 12:25
  • 1
    `curl -s https://www.gov.uk/bank-holidays.json | jq '.. | .date? // empty'` should do the trick ^^ – 0stone0 Jul 22 '20 at 12:27
  • It does do the trick indeed thanks! Would you be able to explain it to me briefly? – jabra Jul 22 '20 at 14:25

1 Answers1

1

To get a stream of the dates for just "england-and-wales" efficiently:

.["england-and-wales"] | .events[] | .date

If you wanted these sorted and "uniquified", simply delay the itemization ([]):

.["england-and-wales"] | .events | map(.date) | unique[]
peak
  • 105,803
  • 17
  • 152
  • 177
  • Looks like this works although the last outout is jq: error (at :0): Cannot iterate over null (null) do you know why that is? – jabra Jul 23 '20 at 12:46
  • @jabra - I ran the jq script against the entire bank-holidays.json file without incident. – peak Jul 24 '20 at 00:35