Home > Net >  Is there any know issues with sending JSON Object as a String in response?
Is there any know issues with sending JSON Object as a String in response?

Time:09-17

I wanted to know is there an any known issues or performance related issues with sending a JSON Object as a string instead of a JSON Object itself ?

Case 1: Sending as a string the response would look like-

{
    "results": {
        "name": "Technical form",
        "jsonobject": "{\"name\":\"value\"}"
        }
    },
    "message": "resource rendered successfully."
}

Case 2: Sending as Object itself-

{
    "results": {
        "name": "Technical form",
        "jsonobject": {
            "name": "value"
            }
        }
    },
    "message": "resource rendered successfully."
}

When the jsonobject grows will there be any performance benefits choosing one over the other, and what would be the best practices related to this ?

CodePudding user response:

Definitely go with option 2. The first option is just asking for trouble. If you are concerned because your JSON response might become very large you might want to consider supporting GraphQL if it makes sense in your case.

With GraphQL you allow the consumer of your API to actually define which JSON attributes he wants to receive when calling an endpoint. If you want to know more, check the following documentation:

  • Related