JSON parsing

I’m trying to parse a response from ChatGPT(OpenAI) api.
This the JSON:

{
    "id": "cmpl-GERzeJQ4lvqPk8SkZu4XMIuR",
    "object": "text_completion",
    "created": 1586839808,
    "model": "text-davinci:003",
    "choices": [
        {
            "text": "\n\nThis is indeed a test",
            "index": 0,
            "logprobs": null,
            "finish_reason": "length"
        }
    ],
    "usage": {
        "prompt_tokens": 5,
        "completion_tokens": 7,
        "total_tokens": 12
    }
}

I need the first array element of child (Choices), " text". I can Iterate over the values but I can’t get the “text” elements value… anybody?

Choices is an array of objects (Dictionary in Xojo).

var json as Dictionary = ParseJSON( aiResponse )
var choices() as variant = json.Value( "choices" )
var firstChoice as Dictionary = choices( 0 )
var choiceText as string = firstChoice.Value( "text" )
1 Like

AHH!. Thanks Kem.