json - 将 2 个黄瓜 JSON 报告与 ruby 进行比较
问题描述
问题是:我有 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
}
}
]
},
解决方案
由于您要的是宝石,因此您可以尝试iteraptor
我已经为此类任务创建了确切的内容。
它允许迭代、映射和减少深度嵌套的结构。例如,要过滤掉"name"
所有级别上调用的所有键,您可以这样做:
input.iteraptor.reject(/name/)
更详细的描述可以在上面链接的 github 页面上找到。
推荐阅读
- git - 不能将 2 个本地分支设置为同一个上游远程
- javascript - 未找到 Service Worker 端点
- javascript - JavaScript:将 Json 数据数组更改为新格式
- javascript - D3.JS V5:错误:
属性 d:预期数字,“MNaN,242.20533333…” - amazon-web-services - 具有 503 服务的 Aws wordpress EC2 不可用
- javascript - Paypal Pass 项目 sku 和订单参考 ID
- java - 不能在java中使用来自sql的Varchar变量作为String
- html - 离子刷新背景是黑色而不是白色错误
- c++ - C++ 类成员函数别名模板防止大括号括起来的初始值设定项列表被识别为对/元组
- python - AttributeError:“RefVariable”对象在非急切执行模式下没有属性“_id”