How to set target_key to a variable value #197
-
Hello @jshlbrd! I'm trying to reformat a log in this format:
to:
I'm struggling to understand how to have the
Any ideas on how to do this? Thanks :) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Hey @nishaprabhakar! 👋 Feel free to tag @brexhq/substation next time if you want to get the team's attention. I don't think this is possible to do, and at the moment I'm not sure how to best support that functionality (maybe another team member will have other ideas). Usually I would recommend formatting JSON objects into key-value pairs where the key is consistent -- for example, without knowing your use case, I would convert the original event to this: {
"type": "A",
"value": "B"
} The issue you're likely to run into with a format like {
"foo": "fooer"
}
{
"bar": "barre"
}
{
"baz": "bazar"
} These objects will be difficult to access in most systems that rely on a JSON schema. But, if that doesn't work for you, then the only solution I can think of that fits the design of the project is a new sub.tf.meta.object.invert({
object: {target_key: 'key'},
transform: sub.obj.copy({object: {source_key: 'value.stringValue'}),
}), ... where the key placed into the JSON object is the value of {
"key": "A",
"value": {
"stringValue": "B"
},
"A": "B"
} |
Beta Was this translation helpful? Give feedback.
@nishaprabhakar Since your JSON schema is consistent, this will work for what you want to do: