Skip to content

json.Unescape has issues with UNC paths #121

@richard-mauri

Description

@richard-mauri

I have a test string that has a value with an escaped UNC path in it .
It validates ok according to: https://jsonlint.com/

"{\"dataPath\":\"\\\\bnk11977fs\\bnk11977\\xyz11146682\\xyzdata\\\"}"

When you pass it through json.Unescape the result is invalid json

See: playground

Highlights from the stdout are:

raw sample0 "\"{\\\"dataPath\\\":\\\"\\\\\\\\bnk11977fs\\\\bnk11977\\\\be11146682\\\\encompassdata\\\\\\\"}\""

unescape for sample0 was invalidated "{\"dataPath\":\"\\\\bnk11977fs\\bnk11977\\be11146682\\encompassdata\\\"}" ; error=json: invalid character 'e' in string escape code: "\\bnk11977fs\bnk11977\be1114668...

You may ask, "If the original is valid json, then why do you need to unescape it anyway?"

Answer: The raw escaped form comes from reading a logging entry.
A log processor service (lambda) needs to create output without all the escapes, else another downstream reader (logstash ingest) see's the dcument event as a big ass string and not a nice nested object.

So the goal is to be able to have the lambda processor write the line something like the following.
yes the UNC and escapes are a bitch

And this is a simple example. Imagine a raw json with 100 deply nested fields.
You certinly can't just blind Replacement of backslash-quote with quote !

{"dataPath":"\\bnk11977fs\bnk11977\be11146682\encompassdata\"}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions