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.

Raw JSON string as field value

See original GitHub issue

I have a large JSON string data field. I want to return this json string asis without first deserializing it to a python object, and serialize back when it gets sent out. What is the best way to do this?

I saw the JSONString type, but not sure if that is intended for this use. Note that I don’t need type checking on this field. Just want to return the string as JSON data object without the overhead of deserialization and serialization.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
geyangcommented, Apr 10, 2019

@ProjectCheshire kindly offered this example that allows one to override the serialization logic:

class JSONScalar(Scalar):
    """
    Arbitrary JSON Properties for features
    """

    @staticmethod
    def serialize(value):
        return value

    @staticmethod
    def parse_literal(node):
        return node.value

    @staticmethod
    def parse_value(value):
        return value
1reaction
geyangcommented, Mar 16, 2019

Hey @jkimbo! Thanks for your reply!

I consider this to be a problem on the serving-side, as an implementation detail behind the graphQL schema.

Suppose I have a large JSON string (5MB) that is read from postgreSQL. Deserializing it into python object, then serialize back is unnecessary. Would be nice if we could __insertUnsafeJson__ into the final graphQL response.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Raw string field value in JSON file - Stack Overflow
A workaround for the lack of raw string support in JSON is to Base64 encode your string before adding it to your JSON....
Read more >
How to handle stringified raw JSON data using JSON Parser?
If a key in your raw JSON data has the value of a string , the syntax should be "A": "" . This...
Read more >
Using @JsonRawValue to serialize property as it is - LogicBig
@JsonRawValue annotation can be used to serialize property as it is. The value is not escaped or quoted. This can be useful in...
Read more >
JSON - HTTPie 3.2.1 (latest) docs
Non-string JSON fields use the := separator, which allows you to embed arbitrary JSON data into the resulting JSON object. Additionally, text and...
Read more >
How to look at the raw string value of a JSON? : r/elm - Reddit
I'm trying to use Browser.Events.onKeyUp , that wants to be passed a JSON decoder as its argument. To write the decoder, I'd like...
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