Splitting json message based on the matching field name #2252
sesa657547
started this conversation in
General
Replies: 2 comments 5 replies
-
Hey @sesa657547 👋 Here's how I'd do it: input:
generate:
count: 1
mapping: |
root = [
{
"dId": "kjglsjglfkgfdkgfhjfhdsj",
"d1": "fhkfjsaf",
"d2": {
"dc1": 8,
"dc2": 9
},
"timestamp": "2020-09-03",
"A": [
{
"aId": "jflksflskgskg",
"af1": "kkfls",
"af2": {
"ac1": 6,
"ac2": 2
},
"af3": 1,
"af4": "00",
"af5": 4
}
],
"B": [
{
"bId": "jgljgldjgs",
"bf1": 6,
"bf2": {
"bc1": 4,
"bc2": 2
}
}
],
"C": [
{
"cId": "njfglsjg",
"cf1": 3,
"cf2": "jfgg"
}
]
}
]
processors:
- mapping: |
root = this.0.with("A", "B", "C").key_values()
- unarchive:
format: json_array
- mapping: |
meta key = this.key
root = this.value
output:
kafka:
# ...
topic: ${! @key }
# ... I used the If |
Beta Was this translation helpful? Give feedback.
4 replies
-
Moving to discussion (#2026) |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
I am new to benthos and on the process of learning it. I have got a situation where I need to split the single payload into multiple messages based on the field names and send these messaged to different kafka topics. My payload looks like this:
[
{
"dId": "kjglsjglfkgfdkgfhjfhdsj",
"d1": "fhkfjsaf",
"d2": {
"dc1": 8,
"dc2": 9
},
"timestamp": "2020-09-03",
"A": [
{
"aId": "jflksflskgskg",
"af1": "kkfls",
"af2": {
"ac1": 6,
"ac2": 2
},
"af3": 1,
]
I want to send A array data to one kafka topics and similarly for B and C.
Thanks
M
Beta Was this translation helpful? Give feedback.
All reactions