question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

JSONString return backslashes

See original GitHub issue

I’m trying to use graphene JSONString to query/mutate a django jsonfield, but in the both cases I receive/send this:

{
  "data": {
    "TitleType": [
      {
        "id": "1",
        "name": "My First Title",
        "fields": "{\"a\": \"b\"}"
      }
    ]
  }
}

can you guys tell me how can I avoid the backslashes in both cases?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
ekampfcommented, May 29, 2019

from graphene.types.generic import GenericScalar

3reactions
ekampfcommented, May 29, 2019

You can’t avoid backlashes because that how JSON strings look. According to JSON spec, JSON values have to use double quotes - " So if you have a JSON value inside a a string value that’s in a JSON, you cant use the inner " chars will break the outer JSON, you have to backslash them.

An alternative would be to use GenericScalar instead of JSONString. In that case your value will be returned as a JSON object and not a string, like this:

{
  "data": {
    "TitleType": [
      {
        "id": "1",
        "name": "My First Title",
        "fields": {"a": "b"}
      }
    ]
  }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Return Json, but it includes backward slashes "\", which I don't ...
Most likely, the slashes are an artifact because you copied them out of the VisualStudio debugger. The debugger displays all strings in a...
Read more >
JSON returning backslashes - MSDN - Microsoft
Hi i have the following which returns json, however it is returning data with backslashes. public string getUserInfo(string UserID) { Users ...
Read more >
How to remove backslash from json data in C#? - CodeProject
The answer is simple: there is no backslash in the string! What you're seeing is the Visual Studio debugger's representation of the string....
Read more >
Remove back slash from response - Salesforce Developers
To remove the backslash you have to write the blob value of the JSON String into the body directly in the RestContext. You...
Read more >
Best Json Escape Characters, Double Quotes and Backslash ...
Backspace is replaced with \b, Form feed is replaced with \f, Newline is replaced with \n, Carriage return is replaced with \r, Tab...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found