Decode ascii hex from string or Convert Charset of a Field on the fly (filters)

I have a case, that a numb cliente sends me a http request with all UTF-8 chaset, but the payload comes with ascii hex, like: "\x22", "\xC3" "\xA2", and so on...

How can I DECODE only this string field, so I can proceed with my filter chain?

Example of the received JSON received:

    {\x22appid\x22:\x22000000000000001\x22,\x22devid\x22:\x22CN6Z8Eka3FSQ9IA\x22,\x22hash\x22:\x226DA58601C8DF15A\x22,\x22hwid\x22:\x22938F281AE5EB32B1\x22,\x22info\x22:{\x22city\x22:\x22Uberl\xC3\xA2ndia\x22,\x22country\x22:\x22Brasil\x22,\x22neighborhood\x22:\x22Alto Umuarama\x22,\x22state\x22:\x22Minas Gerais\x22,\x22country_code\x22:\x22BR\x22},\x22locations\x22:[{\x22lat\x22:-18.8827592,\x22lng\x22:-48.2485458,\x22time\x22:1456682328}]}

Using gsub I cant replace some codes, but this seems not to be the best solution. And even removing the "\x22" codes em put in place a double quote, logstash put a backsh before that "

Example using gsub => [ "field", "\x22", '"'], returns

      {\"appid\":\"000000000000001\",\"devid\":\"CN6Z8Eka3FSQ9IA\",\"hash\":\"6DA58601C8DF15A\",\"hwid\":\"938F281AE5EB32B1\",\"info\":{\"city\":\"Uberl\\xC3\\xA2ndia\",\"country\":\"Brasil\",\"neighborhood\":\"Alto Umuarama\",\"state\":\"Minas Gerais\",\"country_code\":\"BR\"},\"locations\":[{\"lat\":-18.8827592,\"lng\":-48.2485458,\"time\":1456682328}]}

Ooohh, backssashes... afff heheheehe

You can see that the backslashes don't ge away, I thik this is causing the "_jsonparsefailure" error message.

Do I forget something, like a rookie thin? To many hours working... ehehhehe

Regards!

If it helps, here is what I trying to do:

            mutate {
                gsub => [ 'body', '\\x22', '"']
            }
            json {
                source => "body"
                target => "data"
            }
1 Like