【发布时间】:2018-11-21 10:43:11
【问题描述】:
问题是:我有 2 份 JSON 格式的黄瓜测试报告 我需要从这些报告中删除多余的键值对并进行比较,但我无法理解如何从这 2 个 json 中删除不必要的数据,因为它们在 JSON.parse 之后的结构(具有许多嵌套数组/散列的数组或散列)。请告知是否有一些宝石或已知的解决方案可以做到这一点 JSON结构是例如:
[
{
"uri": "features/home_screen.feature",
"id": "as-a-user-i-want-to-explore-home-screen",
"keyword": "Feature",
"name": "As a user I want to explore home screen",
"description": "",
"line": 2,
"tags": [
{
"name": "@home_screen",
"line": 1
}
],
"elements": [
{
"keyword": "Background",
"name": "",
"description": "",
"line": 3,
"type": "background",
"before": [
{
"match": {
"location": "features/step_definitions/support/hooks.rb:1"
},
"result": {
"status": "passed",
"duration": 505329000
}
}
],
"steps": [
{
"keyword": "Given ",
"name": "I click OK button in popup",
"line": 4,
"match": {
"location": "features/step_definitions/registration_steps.rb:91"
},
"result": {
"status": "passed",
"duration": 2329140000
}
},
{
"keyword": "And ",
"name": "I click Allow button in popup",
"line": 5,
"match": {
"location": "features/step_definitions/registration_steps.rb:96"
},
"result": {
"status": "passed",
"duration": 1861776000
}
}
]
},
【问题讨论】:
-
您是否在寻找比较 json 或 hashes 的 gem?
-
您可以尝试
iteraptor我为此类任务创建的 gem。它允许迭代、映射和减少深度嵌套的结构。 -
@AlekseiMatiushkin 很有趣,现在试试,我会及时通知你结果
-
@AlekseiMatiushkin 看起来这正是我所需要的,非常感谢
-
@Mikhah 很酷,欢迎。