Trouble Parsing JSON

Hello all,

Was wondering if anyone can advise me please.

I'm having trouble parsing a json returned from the chatGPT API in a variable called testJson.

{
   "id":"chatcmpl-6sfdslkja;sldfkasjAyVI1vY1MKh",
   "object":"chat.completion",
   "created":1679031810,
   "model":"gpt-3.5-turbo-0301",
   "usage":{
      "prompt_tokens":9,
      "completion_tokens":13,
      "total_tokens":52
   },
   "choices":[
      {
         "message":{
            "role":"assistant",
            "content":"\n\nPlease check your local weather forecast or a weather website or app for the latest information."
         },
         "finish_reason":"stop",
         "index":0
      }
   ]
}

I'm parsing with this variable but am receiving a blank:

%JSONValue%testJson.id%

Simpler jsons seem to be working but not this one. Any help would be much appreciated. Thanks!

This issue is being caused by the newline characters in testJson.choices[1].message.content.

Assuming you're using Set Variable to Text, it defaults to "Process Text Normally", which converts those \n control characters to newlines (which invalidate your JSON).

Using the action (gear) :gear: menu, you can change this setting to "Process Nothing", which should clear things up.

5 Likes

Thanks avtraino, I never encountered this setting before.

Much appreciated - my JSON parsing works now.