gpt4 book ai didi

Golang 相当于 `jq --stream -c`

转载 作者:IT王子 更新时间:2023-10-29 02:21:56 28 4
gpt4 key购买 nike

在命令行上使用 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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com