convert object to json string #488
Answered
by
jszwedko
camilisette
asked this question in
Q&A
-
Has anyone been able to convert an object to a json string? For example this incoming log: {
"timestamp": "2022-06-17T16:31:26.123Z",
"level": "info",
"message": "User login successful",
"user": {
"id": "12345",
"name": "johndoe",
"details": {
"country": "USA",
"city": "New York"
}
},
"request": {
"ip": "192.168.1.1",
"user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537"
}
} Will be converted to this: {
"timestamp": "2022-06-17T16:31:26.123Z",
"level": "info",
"message": "User login successful",
"user": "{\"id\": \"12345\", \"name\": \"johndoe\", \"details\": {\"country\": \"USA\", \"city\": \"New York\"}}",
"request": {
"ip": "192.168.1.1",
"user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537"
}
} |
Beta Was this translation helpful? Give feedback.
Answered by
jszwedko
Oct 2, 2023
Replies: 1 comment 1 reply
-
Something like: |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
camilisette
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Something like:
.user = encode_json!(.user)
should work for you.