gpt4 book ai didi

json - sed 替换 json 对象中键的值

转载 作者:行者123 更新时间:2023-12-03 19:37:56 25 4
gpt4 key购买 nike

我想做什么?

给定一个 json 事件文件。我想通过关键字定位特定事件,然后用“”替换该事件中键的值。
这必须用 sed 完成(Splunk 转发问题。我不会让你厌烦细节)。

示例事件

{
"message":"we have a response from SomeService",
"other":"some stuff",
"other2":"some other stuff",
"xml":"<Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:awsse=\"http://xml.chicken.com/2010/06/Session_v3\" xmlns:wsa=\"http://www.w3.org/2005/08/addressing\"><Header><To>http://www.w3.org/2005/08/addressing/anonymous</To><From><Address>..... AND SO ON BIG GIANT NASTEY XML",
"other3":"even more stuff"
}

预期结果
{
"message":"we have a response from SomeService",
"other":"some stuff",
"other2":"some other stuff",
"xml":"",
"other3":"even more stuff"
}

我尝试了什么?
我可以隔离事件并更换 key 没问题。我正在努力使用正则表达式来替换 json 中键的值。
cat test.json | sed '/"we have a response from SomeService"/ s/other2/chicken/'

谢谢你的帮助!

最佳答案

从评论复制

你可以试试这个

cat test.json | sed '/"xml":/ s/"xml":[^,]*/"xml":""/'
[^,]*将匹配所有内容,直到 ,正在寻找。

关于json - sed 替换 json 对象中键的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45464280/

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