- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
在命令行上使用 jq --stream -c
,我可以像这样格式化漂亮的 JSON:
{
"object": {
"something": {
"key1": 123,
"key2": 456
},
"something_else": {
"key1": [
"value1",
"value2"
]
}
}
}
进入这个:
[["object","something","key1"],123]
[["object","something","key2"],456]
[["object","something","key2"]]
[["object","something_else","key1",0],"value1"]
[["object","something_else","key1",1],"value2"]
[["object","something_else","key1",1]]
[["object","something_else","key1"]]
[["object","something_else"]]
[["object"]]
我查看了 Golang documentation for JSON 但找不到任何类似的东西。有这样的功能我错过了吗?
更准确地说,我想像这样打印上面的 JSON:
object.something.key1=123
object.something.key2=345
object.something_else.key1.0=value1
object.something_else.key1.1=value2
最佳答案
I've looked through the Golang documentation for JSON but couldn't find anything similar. Is there such a function that I've missed?
不,你没有错过任何东西。当前的 JSON 库不支持您描述的“开箱即用”。
如果你想让它工作,你需要找到一个包,提供你需要的灵 active 或满足 json.Marshaler
自己使用自定义类型。
关于Golang 相当于 `jq --stream -c`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44243492/
我在数组中有一系列 [timestamp, count] 对,我想使用 jq 计算每个时间戳的累积和。我怎么能那样做? 这里是一个示例数据集: [ [1431047957699, 1], [1
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a softwar
我在数组中有一系列 [timestamp, count] 对,我想使用 jq 计算每个时间戳的累积和。我怎么能那样做? 这里是一个示例数据集: [ [1431047957699, 1], [1
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a softwar
我很好奇是否有一种干净的方法可以将行号添加到 jq 的输出,同时仍然保留输出的颜色。我已经尝试从 jq 到 cat -n 的管道,但不幸的是,这删除了在遍历 JSON 树时有很大帮助的着色。 最佳答案
我有一些看起来像json数据: { "p": { "d": { "a" : { "r": "foo", "g": 1 },
我正在使用 jq 在大文件中搜索特定结果。我不关心与此特定条件匹配的重复条目,并且处理整个文件需要一段时间。我想做的是打印有关第一场比赛的一些详细信息,然后在文件上终止 jq 命令以节省时间。 IE。
给定以下 JSON 文件 foo.js(为清楚起见已删除): {"a":{"b":[{"x":{"x1":1},"y":{"y1":5}},{"x":{"x1":1},"y":{"y1":6}}]}}
我需要从一些 JSON 中一次删除多个键(使用 jq ),并且我正在尝试了解是否有比每次调用 map 和 del 更好的方法。这是我的输入数据: test.json [ { "label"
我正在使用 jq 来解析日志数据,偶尔日志包含格式错误的内容(无效的 json),当发生这种情况时,jq 会在此时中止处理。 有没有办法让 jq 继续处理它可以做的事情,同时通过 stderr 报告问
我无法理解以下示例中显示的 jq(版本 1.6)更新运算符的行为。 为什么示例 1 返回更新后的对象,而示例 2 和 3 返回空对象或错误结果? 例子之间的区别仅在于将字符串转换为数字的函数的调用顺序
给定 [3,4] [5,2] 我想制作: [5,2] [3,4] 我试过了,但失败了: echo '[3,4] [5,2]' | jq 'sort_by(.[1])' jq: error (at :1
我有一个要用 JQ 处理的 JSON 文件。它在另一个对象中有一个对象数组,带有一个我想用来填充新数组的键。 在我的实际用例中,它嵌套在许多其他的绒毛中,还有更多的数组,但将其作为此类事物的一个更简单
我有这个 jq筛选: some_command | jq -r '.elements[] | select(.state=="LIVE" and .group == "some_text" and .
我无法理解以下示例中显示的 jq(版本 1.6)更新运算符的行为。 为什么示例 1 返回更新后的对象,而示例 2 和 3 返回空对象或错误结果? 例子之间的区别仅在于将字符串转换为数字的函数的调用顺序
给定 [3,4] [5,2] 我想制作: [5,2] [3,4] 我试过了,但失败了: echo '[3,4] [5,2]' | jq 'sort_by(.[1])' jq: error (at :1
我刚刚发现 jq 并且非常喜欢它。一件事我发现自己做了很多事情,比如: result=$(jq --raw-output '.some | .filters // ""') if [[ $result
我一直在尝试使用 chocoletey 安装 jq 但是,当我运行以下命令时,它失败了。 choco install jq 阅读日志文件,我看到它指向 Powershell 脚本指向一个不再存在的 U
json block 数组中的数千个 json block 之一如下所示 - { "id": 4409976, "name": "MKLIU", "version": "1.0", "
json block 数组中的数千个 json block 之一如下所示 - { "id": 4409976, "name": "MKLIU", "version": "1.0", "
我是一名优秀的程序员,十分优秀!