How extract specific output from Json response

Hello All, we are facing challenges in extracting specific out from Json response in String format.
The given below is sample output response.
{“id”:“chatcmpl-7TQErCPiyCSHplw6BoGYHEnmnLFfu”,“object”:“chat.completion”,“created”:1687246729,“model”:“gpt-35-turbo”,“choices”:[{“index”:0,“finish_reason”:“stop”,“message”:{“role”:“assistant”,“content”:“False.”}}],“usage”:{“completion_tokens”:2,“prompt_tokens”:29,“total_tokens”:31}}

From the above output we need to know if content is False or true, is short what is value of content from above response output.
Can someone help us this issue.

@Ripusudan_Sharma

Please use deserialize json activity and from
The output use this(assuming output is in variable jobj)

Jobj("choices")(0)("message")("content").ToString

Cheers

1 Like

Hi @Ripusudan_Sharma

Please take a look at the following structure:

Imports Newtonsoft.Json.Linq

Dim jsonObject As JObject = JObject.Parse(jsonResponse)
Dim contentValue As String = jsonObject("choices")(0)("message")("content").ToString()

If contentValue = "True" Then
    LogMessage("Content is True")
ElseIf contentValue = "False" Then
    LogMessage("Content is False")
Else
    LogMessage("Content is neither True nor False")
End If

Hope this helps,
Best Regards.

1 Like

@Ripusudan_Sharma
Kindly note that your sample has a dot at the end
we can handle by:

grafik

In case the value is true / false without dot we can do and get back a boolean (second line):
grafik

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.