JSON as Body parameter

Hello,
a function get a parameter string as [FromBody].
It contains a JSON for processing in my function. The JSON must be URL encoded for this to work.

{
"Param": "{ %22name1%22:%22Value1%22, %22Name2%22:%22Value2%22}"
}

Is there any other way to pass an unknown JSON as a parameter to a function?

Thanks
Peter

Alternatively you can set the parameter type as a regular Delphi JSON class, like TJSONValue or TJSONObject. Or use the JSON types from BCL, like TJElement or TJObject.
This way, the client doesn't need to encode the JSON in a string, it can send the pure JSON, like;

{
  "Param": { "name1": "Value1", "Name2": "Value2" }
}

More info: Service Operations | TMS XData documentation

1 Like