1

我是 JSONata 的新手,所以我仍然对它有所了解。我需要从嵌套对象中提取数据,例如:

{
    "transaction": {
        "id": "de112b4b-82e2-4172-a89f-68724c90b692"
    },
    "domain": {
        "id": "realworld"
    },
    "listing": {
        "spanner": {
            "information": {
                "type": {
                    "VENDOR": "Charlie"
                },
                "variables": {
                },
                "uid": "08_spanner",
                "mode": {
                    "store": "bob"
                },
                "version": "1",
                "name": "Harrold"
            }
        },
        "hammer": {
            "information": {
                "type": {
                    "VENDOR": "Cliff"
                },
                "variables": {
                },
                "uid": "08_hammer",
                "mode": {
                    "store": "steve"
                },
                "version": "1",
                "name": "Mike"
            }
        },
        "wrench": {
            "information": {
                "type": {
                    "VENDOR": "Dave"
                },
                "variables": {
                },
                "uid": "08_wrench",
                "mode": {
                    "store": "bob"
                },
                "version": "1",
                "name": "Kent"
            }
        }
    }
}

...我需要用它的“信息”提取列表数据,但没有信息键。所以结果看起来像:

{
    "spanner": {
        "type": {
            "VENDOR": "Charlie"
        },
        "variables": {
        },
        "uid": "08_spanner",
        "mode": {
            "store": "bob"
        },
        "version": "1",
        "name": "Harrold"
    },
    "hammer": {
        "type": {
            "VENDOR": "Cliff"
        },
        "variables": {
        },
        "uid": "08_hammer",
        "mode": {
            "store": "steve"
        },
        "version": "1",
        "name": "Mike"
    },
    "wrench": {
        "type": {
            "VENDOR": "Dave"
        },
        "variables": {
        },
        "uid": "08_wrench",
        "mode": {
            "store": "bob"
        },
        "version": "1",
        "name": "Kent"
    }
}

我一直在http://try.jsonata.org/上闲逛,可以看到这个库有多么强大,但到目前为止还没有成功实现这个目标。任何和所有的帮助表示赞赏:)。

4

1 回答 1

1

以下表达式将执行此操作:

listing.$each(function($value, $key) {
  { $key: $value.information }
}) ~> $merge()

http://try.jsonata.org/S17Erm85z

于 2018-03-26T07:48:58.270 回答