代码之家  ›  专栏  ›  技术社区  ›  Abhijit Sarkar

基于子数组长度提取JSON数组?

  •  -1
  • Abhijit Sarkar  · 技术社区  · 8 年前

    {
        "result": {
            "spaces": [{
                "priceschema": {
                    "prices": [{
                        "costs": [{
                            "amount": "3"
                        }]
                    }]
                }
            }]
        }
    }
    

    prices

    {price: .result.spaces[].priceschema.prices[]?} | select((.price.costs[] | length) > 1)
    

    请注意 costs 可能不存在。

    1 回复  |  直到 8 年前
        1
  •  1
  •   peak    8 年前

    由于您还没有给出显示所需输出格式的示例,因此我只能建议如下:

    .result.spaces[].priceschema.prices[]
    | {price: .}
    | select((.price.costs? | length) > 1)
    

    希望这能引导你找到你想要的答案。