Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not search substrings when JSON is nested #1415

Closed
aikrikunov95 opened this issue Apr 14, 2021 · 2 comments
Closed

Can not search substrings when JSON is nested #1415

aikrikunov95 opened this issue Apr 14, 2021 · 2 comments
Labels

Comments

@aikrikunov95
Copy link

aikrikunov95 commented Apr 14, 2021

I want to write a string which represents nested JSON object to disk and get beginning indexes of some inner objects. The problem is that I store an inner object as string, not JSON object, in order to ensure that a digital signature function will always receive the same input. When I encode the most outer object to string, the inner one becomes escaped and I can't find initial un-escaped version in the resulting string. Consider the following example:

val messageContent = MessageContent(
    type = "createGroup",
    groupTitle = "Test title",
    timestamp = 0
)
val messageContentString = Json.encodeToString(messageContent)

{
    "type":"createGroup",
    "timestamp":0,
    "groupTitle":"My title"
}

val signedMessage = SignedMessage(
    contentString = messageContentString,
    memberPublicKey = "xxx",
    contentSignature = "yyy"
)
val signedMessageString = Json.encodeToString(signedMessage)

{
    "contentString":"
        {
            \"type\":\"createGroup\",
            \"timestamp\":0,
            \"groupTitle\":\"My title\"
        }",
    "memberPublicKey":"xxx",
    "contentSignature":"yyy"
}

I'm trying to search messageContentString in signedMessageString but it's escaped with backslashes and my search fails.

Is there a way to un-escape resulting string so I can search inside it, or should I stop storing JSON objects as strings in general? Thanks.

@sandwwraith
Copy link
Member

There's no way to do this for now, but it looks like a use case for #1405 (comment)

@shanshin
Copy link
Contributor

shanshin commented Nov 2, 2023

Implemented in #2041

@shanshin shanshin closed this as completed Nov 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants