我需要一些过滤数据的帮助。如何过滤这些以显示日期和价格,但我只需要将不可用设置为false的数据。
这些是数据:
{"outbound":{"fares":[{"price":null,"soldOut":false,"unavailable":true,"day":"2016-12-01"},{"price":{"value":39.09,"valueMainUnit":"39","valueFractionalUnit":"09","currencyCode":"EUR","currencySymbol":"€"},"soldOut":false,"unavailable":false,"day":"2016-12-02"},{"price":null,"soldOut":false,"unavailable":true,"day":"2016-12-03"},{"price":{"value":21.24,"valueMainUnit":"21","valueFractionalUnit":"24","currencyCode":"EUR","currencySymbol":"€"},"soldOut":false,"unavailable":false,"day":"2016-12-04"},{"price":{"value":18.74,"valueMainUnit":"18","valueFractionalUnit":"74","currencyCode":"EUR","currencySymbol":"€"},"soldOut":false,"unavailable":false,"day":"2016-12-05"},{"price":null,"soldOut":false,"unavailable":true,"day":"2016-12-06"},{"price":{"value":23.24,"valueMainUnit":"23","valueFractionalUnit":"24","currencyCode":"EUR","currencySymbol":"€"},"soldOut":false,"unavailable":false,"day":"2016-12-07"},{"price":null,"soldOut":false,"unavailable":true,"day":"2016-12-08"},{"price":{"value":32.29,"valueMainUnit":"32","valueFractionalUnit":"29","currencyCode":"EUR","currencySymbol":"€"},"soldOut":false,"unavailable":false,"day":"2016-12-09"},{"price":null,"soldOut":false,"unavailable":true,"day":"2016-12-10"},{"price":{"value":16.99,"valueMainUnit":"16","valueFractionalUnit":"99","currencyCode":"EUR","currencySymbol":"€"},"soldOut":false,"unavailable":false,"day":"2016-12-11"},{"price":{"value":14.99,"valueMainUnit":"14","valueFractionalUnit":"99","currencyCode":"EUR","currencySymbol":"€"},"soldOut":false,"unavailable":false,"day":"2016-12-12"},{"price":null,"soldOut":false,"unavailable":true,"day":"2016-12-13"},{"price":{"value":9.99,"valueMainUnit":"9","valueFractionalUnit":"99","currencyCode":"EUR","currencySymbol":"€"},"soldOut":false,"unavailable":false,"day":"2016-12-14"},{"price":null,"soldOut":false,"unavailable":true,"day":"2016-12-15"},{"price":{"value":26.34,"valueMainUnit":"26","valueFractionalUnit":"34","currencyCode":"EUR","currencySymbol":"€"},"soldOut":false,"unavailable":false,"day":"2016-12-16"},{"price":null,"soldOut":false,"unavailable":true,"day":"2016-12-17"},{"price":{"value":16.99,"valueMainUnit":"16","valueFractionalUnit":"99","currencyCode":"EUR","currencySymbol":"€"},"soldOut":false,"unavailable":false,"day":"2016-12-18"},{"price":{"value":9.99,"valueMainUnit":"9","valueFractionalUnit":"99","currencyCode":"EUR","currencySymbol":"€"},"soldOut":false,"unavailable":false,"day":"2016-12-19"},{"price":null,"soldOut":false,"unavailable":true,"day":"2016-12-20"},{"price":{"value":16.99,"valueMainUnit":"16","valueFractionalUnit":"99","currencyCode":"EUR","currencySymbol":"€"},"soldOut":false,"unavailable":false,"day":"2016-12-21"},{"price":null,"soldOut":false,"unavailable":true,"day":"2016-12-22"},{"price":{"value":21.24,"valueMainUnit":"21","valueFractionalUnit":"24","currencyCode":"EUR","currencySymbol":"€"},"soldOut":false,"unavailable":false,"day":"2016-12-23"},{"price":null,"soldOut":false,"unavailable":true,"day":"2016-12-24"},{"price":null,"soldOut":false,"unavailable":true,"day":"2016-12-25"},{"price":{"value":21.24,"valueMainUnit":"21","valueFractionalUnit":"24","currencyCode":"EUR","currencySymbol":"€"},"soldOut":false,"unavailable":false,"day":"2016-12-26"},{"price":null,"soldOut":false,"unavailable":true,"day":"2016-12-27"},{"price":{"value":45.99,"valueMainUnit":"45","valueFractionalUnit":"99","currencyCode":"EUR","currencySymbol":"€"},"soldOut":false,"unavailable":false,"day":"2016-12-28"},{"price":null,"soldOut":false,"unavailable":true,"day":"2016-12-29"},{"price":{"value":55.99,"valueMainUnit":"55","valueFractionalUnit":"99","currencyCode":"EUR","currencySymbol":"€"},"soldOut":false,"unavailable":false,"day":"2016-12-30"},{"price":null,"soldOut":false,"unavailable":true,"day":"2016-12-31"}],"minFare":{"price":{"value":9.99,"valueMainUnit":"9","valueFractionalUnit":"99","currencyCode":"EUR","currencySymbol":"€"},"soldOut":false,"unavailable":false,"day":"2016-12-14"},"maxFare":{"price":{"value":55.99,"valueMainUnit":"55","valueFractionalUnit":"99","currencyCode":"EUR","currencySymbol":"€"},"soldOut":false,"unavailable":false,"day":"2016-12-30"}}}
答案 0 :(得分:1)
您可以使用jq
之类的JSON解析器来解析您的JSON输入和放大器。查询你想要的任何东西。
假设您的json位于file.json
,以下内容将从fares
数组中提取unavailable
到false
的所有条目,并仅返回day
& ; price
:
jq -r ". | .outbound.fares[] | select(.unavailable == false) | { day: .day, price: .price }" file.json