.. Var MyContent: Text; Begin .. .. MyContent:= '{ "subject": "Something Here", "expiresIn": "15m", "private_key": "-----BEGIN PRIVATE KEY-----Something Here-----END PRIVATE KEY-----", "issuer": "Something Here" }' .. HTTPClient.POST(..,MyContent,..)
MyContent:= '{' + '"subject": "Something Here",' + '"expiresIn": "15m",' + '"private_key": "-----BEGIN PRIVATE KEY-----Something Here-----END PRIVATE KEY-----",' + '"issuer": "Something Here"' + }'
Answers
If you are in AL, you can use json type objects, makes life easier for json, example:
then, I add to payload (text variable):
vPayLoad := '{ "entity":' + vPayLoad + '}';
To solve your issue with single quotations, I suggest you try client.Put(RequestURL, RequestContent, ResponseMessage) as I do below.
JSON is nothing more than text, so the way you are attempting it without JsonObject variable is doable.
The reason you're getting a red underline is because AL C/AL doesn't know how many lines your text is.
Each line must be on it's own, between single quotes, and you can then add it to the next line. See below.
However, Json doesn't need to be perfect with new lines and white spaces.
Below some examples with their output. Any of those should work to create Json for you to send in body.
You see that the first example has the same output as the last one, which uses JsonObject.
But I would still recommend using JsonObject variable since it's a more proper approach.
It also allows you to create more complex Json far easier and more dynamic.
And I think it makes your code more readable, which is great if you have to change something 6 months later .