Suppose a sample API expects the following inputs:
In this case, the 'query' parameter is used to pass the JSON body to the API server.
Let's test some sample JSON bodies being passed to the API server and review their results.
1) Passing the query as an invalid JSON :- {image/png}
-> This errors out as
As observed, this is not a valid JSON and hence errors out.
Note: The validity of any JSON can be checked at https://jsonlint.com/
2) Passing a valid JSON i.e. with key and value:- {"pkg.query":"{image/png}"}
A valid JSON body will always produce the correct result, assuming all other aspects of the API call are handled properly.
3) If the user wants to use the same JSON value as in point #1, i.e.,
{image/png}
, there is a workaround: simply add a space character before the parameter.
In this case, there is a space in front of the invalid JSON body. The reason that adding a space before the query works is due to specific logic implemented in the code. If the input does not begin with
}
or
{{}{}
, it is processed by a separate logic path that handles queries. This design ensures that queries are routed through the original code handling mechanism.
Please be advised that it is recommended to follow the standard and valid JSON body inputs and avoid relying on the workaround, as it may not be supported in future releases of TDV.