- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
尽管进行了大量研究,我还是找不到解决方案。我被 contains 函数困住了。我有这个 Json 文件:
{
"from": "Api",
"success": true,
"message": "",
"errors": [],
"data": {
"operations": [
{
"IDOperation": 100,
"DateEcriture": "2019-01-02",
"Comment": "Invoice Nh5 numero 152",
"sous_operations": []
},
{
"IDOperation": 101,
"DateEcriture": "2019-01-02",
"Comment": "one other thing",
"sous_operations": []
},
{
"IDOperation":102,
"DateEcriture": "2019-01-02",
"Comment": "an other thing",
"sous_operations": [{"ID-sous-Operation": 103,
"DateEcriture": "2019-01-02",
"Comment": "Invoice Nh15 numero 341"}]
}]
}
}
我想过滤“注释”字段中包含“发票”一词的对象以获得以下结果:
{"operations": [
{
"IDOperation": 100,
"DateEcriture": "2019-01-02",
"Comment": "Invoice Nh5 numero 152"
},
{
"IDOperation": 103,
"DateEcriture": "2019-01-02",
"Comment": "Invoice Nh15 numero 341"
}]
}
感谢您的帮助
最佳答案
您还没有说明您在哪一部分上遇到困难。我猜它正在处理嵌套子操作,因为这对我来说似乎是最难和最不明显的部分,但我会尽力涵盖所有内容。
这是我的假设:
data
的对象组成。data
字段始终是一个带有字段 operations
的对象。操作
始终是一个数组。operations
的每个成员都有相同的四个字段:IDOperation
、DateEcriture
、Comment
、 sous_操作
。sous_operations
始终是一个数组。sous_operations
的每个成员都具有相同的三个字段:ID-sous-Operation
(!)、DateEcriture
和 Comment
。Comment
的字段都是字符串。Comment
字段中包含“Invoice”(不区分大小写)的工序和子工序。ID-sous-Operation
重命名为 IDOperation
。操作
的对象组成,该字段是选定和转换操作的数组。我认为这符合你的要求:
{
operations:
data.operations|
map(
&[
[
{
IDOperation:IDOperation,
DateEcriture:DateEcriture,
Comment:Comment
}
],
map(
&{
IDOperation:"ID-sous-Operation",
DateEcriture:DateEcriture,
Comment:Comment
},
sous_operations
)
],
@
)|
[][]|
[?contains(Comment,`"Invoice"`)]
}
首先,我们用一个二元数组替换每个操作。第一个成员是一个单元素数组,包含操作的字段,但不包含其子操作。第二个成员是所有操作的子操作的数组。 (此时我们还重命名了子操作ID字段。)
现在我们的操作是一个由简化操作数组组成的(两个元素)数组组成的数组。我们使用展平运算符两次来获得一个简单的单层数组。最后我们简单地使用 contains 方法对其进行过滤。
这是输出:
$ jp --filename input1.json --expr-file filter.jmespath
{
"operations": [
{
"Comment": "Invoice Nh5 numero 152",
"DateEcriture": "2019-01-02",
"IDOperation": 100
},
{
"Comment": "Invoice Nh15 numero 341",
"DateEcriture": "2019-01-02",
"IDOperation": 103
}
]
}
关于json - 使用字符串过滤 JMESPath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60380325/
在 jq 过滤语言中,. 过滤器表达式简单地返回输入的 JSON 不变( pretty-print 除外)。例如 $ echo '{"foo": true, "bar": 42}' | jq '.'
我有一个 JSON,我需要使用 JMESPATH 选择人员角色的值。我可以仅使用一个静态 id 来完成此操作,例如 roles[?id=='1324'],但我无法使用从 JSON 中选择的角色 id
我有一个包含两个数组的 JSON 对象 - 一个 keys 数组和一个 values 数组,两者的长度相同。使用 jmespath,我想使用 keys 数组的值作为键,使用 values 数组的值作为
我正在尝试查找恰好具有 2 个内核的所有虚拟机: $ az vm list-sizes -o json --query "[?numberOfCores == 2]" az vm list-sizes
我有一个使用 JMESPath 解析的对象,其中属性的值是编码为字符串的 JSON 对象。我希望能够将该字符串属性解析为 JSON 对象并仅使用 JMESPath 使用它(我知道我可以使用 JSON
以下 JmesPath 表达式查找已标记为团队的实例: "Instances[?Tags[?Key=='team']]" 您知道如何查找未标记为团队的实例吗? 我试过了: "Instances[?!T
我有一个 JSON { "key": "processId-29231", "fields": { "attachment": [ { "id": "7
我有一个字典列表,其中一个字段中包含另一个列表。我想“展平”该列表,因此它为我提供了每个子元素,并将父元素中的一个字段(或某些字段)复制到其中。示例: 源数据: [ { "na
是否可以编写 JMESPath 表达式以返回设置了特定子属性值的对象名称列表?在下面的示例中,我想获取所有主机名的列表,其中 fileexists.stat.exists 设置为 true。 我的目标
我一直在研究 JMESPath 的官方文档和一些其他资源。但是我没有成功完成以下任务: 我的数据结构是来自 vimeo api(视频列表)的 json:数据数组包含很多对象,每个对象都是上传的文件,有
我有以下示例 json 文档(对象的对象): { "key1": { "key1a": [{"key1aa": "value1aa"}, {"key1ab": "value1ab"}],...
在带有此查询的 JMESPath 中: people[].{"index":@.index,"name":name, "state":state.name} 在此示例数据上: { "people"
我意识到这里还有其他几个 JmesPath 连接问题,但是我遇到了一个单独的问题,我没有找到任何示例,我需要连接(即连接)一组动态的 JSON 值 -命名键合并为单个元素。 如果我从以下 JSON 数
使用 JMESPath,是否可以根据输入中是否存在多个键/值对来过滤输出? 从下面的示例 JSON 中,我想要做的是仅提取 Tags 中包含这些键/值对的对象 - Environment / ABC
尽管进行了大量研究,我还是找不到解决方案。我被 contains 函数困住了。我有这个 Json 文件: { "from": "Api", "success": true, "me
尽管进行了大量研究,我还是找不到解决方案。我被 contains 函数困住了。我有这个 Json 文件: { "from": "Api", "success": true, "me
我正在尝试将 Ansible 脚本转换为 Python AWS lambda 函数。在我的 Python 脚本中,我使用 jmespath library按日期过滤,日期以 ISO 8601 格式的字
有一个如下所示的对象: { "pick": "a", "elements": [ {"id": "a", "label": "First"}, {"id": "b", "lab
我正在寻找使用 JMESPath 更改 3rd 方 API 的数据结构,但一直无法弄清楚如何获取键值对的单个对象并将其重构为对象数组,每个对象都包含键值对。 我已经浏览了所有 JMESPath doc
假设我有 json: [ [0, "a"], [1, "b"], [2, "c"] ] 如何创建 JMESPath 投影以获取: [ {"id": 0, "name": "a"}, {"
我是一名优秀的程序员,十分优秀!