json - 使用 JQ 将字段名称提取到新对象中
问题描述
Spring 在 env-endpoint 提供有关环境的信息。我想简化输出,看起来像这样:
{
"propertySources": [
{
"name": "ports",
"properties": {
"server.port": {
"value": 9110
},
"management.port": {
"value": 9350
}
}
},
{
"name": "trees",
"properties": {
"oak": {
"value": "true"
}
}
},
{
"name": "elephants",
"properties": {}
},
...
}
我只想将键值对视为输出,如下所示:
{
"server.port": 9110,
"management.port": 9350,
"oak": "true",
...
}
使用 JQ 我尝试了一些从
curl https://localhost:9350/actuator/env/ -s | jq '[.propertySources[].properties[]]'
并尝试map
,select
并且with_entries
,但我无法让它运行。你能给我一个正确的方向吗?
解决方案
您可以简单地添加properties
对象,但为了获得该输出作为回报,您也需要取出value
字段。
.propertySources | map(.properties) | add | map_values(.value)
推荐阅读
- c# - System.Data.Services.Client.DataServiceContext 超时属性不起作用
- javascript - 导航栏对底层背景透明
- python - 附加多个 pyplot.subplots - 如何?
- java - 一旦布尔值为真,如何关闭 JFrame?
- c# - 需要从装饰器设计模式中的组件派生装饰器
- spring-boot - 如何增加reactor WebClient的工作线程?
- qt - 在 ListView 中,如何将 currentIndex 或 currentItem 设置为动态创建的元素?
- node.js - 如何在 gitlab-runner 中启动服务器?
- asp.net - 为什么我们需要 ASP.NET 模拟:在 IIS 6.0 上为默认网站启用?
- wordpress - 如何通过编码在 WordPress 中创建照片库?