vectordotdev / vrl

Vector Remap Language
Mozilla Public License 2.0
124 stars 56 forks source link

Convert object to string. #950

Closed evanzhang87 closed 1 month ago

evanzhang87 commented 1 month ago

A note for the community

Use Cases

{
    "key_l1": "value",
    "key_l1_2": {
        "key_l2": "hello"
    },
    "key_l1_3": {
        "key_l2_2": {
            "key_l3": "hello"
        }
    }
}

For multi level json message, I want to flatten only just one level, like this:

{
    "key_l1": "value",
    "key_l1_2_key_l2": "hello",
    "key_l1_3_key_l2_2": {
         "key_l3": "hello"
    }
}

But I think it's more common to convert object to string.

Attempted Solutions

No response

Proposal

No response

References

No response

Version

No response

jszwedko commented 1 month ago

Hi @evanzhang87 ,

Am I understanding correctly that you want to use flatten but only have it flatten one level? The title of this issue is a bit confusing.

evanzhang87 commented 1 month ago

Sorry, I want to make a json string value, like {\"key_l3\": \"hello\"}", my value is from a multi level json, so I want to flatten one level, but it's not so important, because I can use vrl : .keyl1_l2 = .keyl1.l2

jszwedko commented 1 month ago

Ah, you can turn an object into a JSON string via https://vector.dev/docs/reference/vrl/functions/#encode_json . Is that what you mean?

evanzhang87 commented 1 month ago

Wow, it works! thx~