This message originated from Cribl Community Slack.
Click here to view the original link.
I have a dict that contains base64-encoded fields. How can I decode them all without knowing their names?
Solved
Dictionary Base64 Decoding Without Knowing Field Names
Best answer by David Maislin
You can decode all base64-encoded fields in a dictionary in Cribl Stream using an expression that iterates over the object’s keys and decodes each value. Since you don’t know the field names in advance, use Object.keys and a loop in an Eval function.
Here’s an example for use in an Code function which you can update for your use case too.
let decoded = {};
for (let k of Object.keys(dict)) {
try {
decoded[k] = C.Decode.base64(dict[k]);
} catch (e) {
decoded[k] = dict[k]; // fallback if not valid base64
}
}
decoded
- Replace dict with your actual field name.
- This will attempt to base64-decode every value; if decoding fails (e.g., not valid base64), it leaves the original value.
- You can assign the result to a new field or overwrite the original.
for (let k of Object.keys(dict)) {
try {
dict[k] = C.Decode.base64(dict[k]);
} catch (e) {
// leave as is
}
}
dict
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.
