/ / sed per sostituire il valore per una chiave in un oggetto json: json, regex, sed, replace

sed per sostituire il valore di una chiave in un oggetto json: json, regex, sed, sostituisci

Cosa sto cercando di fare?

Dato un file di eventi JSON.Voglio individuare eventi specifici per parola chiave e quindi sostituire il valore della chiave in quell'evento con "". Questo deve essere fatto con sed (problema di inoltro Splunk .. Non ti annoierò con i dettagli).

Evento di esempio

{
"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"
}

Risultato desiderato

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

Che cosa ho provato? Posso isolare gli eventi e sostituire una chiave senza problemi. Sto lottando con una regex per sostituire il file valore di una chiave nel json.

cat test.json | sed "/"we have a response from SomeService"/ s/other2/chicken/"

Grazie per il tuo aiuto!

risposte:

1 per risposta № 1

copia dal commento

Potresti provare questo

cat test.json | sed "/"xml":/ s/"xml":[^,]*/"xml":""/"

[^,]* corrisponderà a tutto fino a , essere trovare.