JSON decoding trouble

I got this returned data (in a variable “curlRet”):

{
  "object": "list",
  "data": [
    {
      "id": "msg_12345",
      "object": "thread.message",
      "created_at": 1711974085,
      "assistant_id": "asst_12345",
      "thread_id": "thread_12345",
      "run_id": "run_12345",
      "role": "assistant",
      "content": [
        {
          "type": "text",
          "text": {
            "value": "Vannevar Bush, considered the *grandfather* of hypertext, proposed the Memex system in 1945, a concept described as a \"memory extender\" for organizing and accessing information efficiently. The Memex, a mechanized private file and library, stored information on microfilm with features like a scanner for input, note-taking capabilities, and associative indexing. Bush aimed to address the expanding scientific information, emphasizing the need for better information access. Although the Memex was not constructed, it laid the groundwork for advanced computing concepts. The Memex discussion sparked interest and inspired future innovators but wasn't fully realized due to technological limitations.",
            "annotations": []
          }
        }
      ],
      "file_ids": [],
      "metadata": {}
    }
  ],
  "first_id": "msg_12345",
  "last_id": "msg_12345",
  "has_more": true
}

I used this call to extract the important part:

var:string theNewValue = curlRet.json["data"]["content"][0]["text"][1]["value"];

But the returned value is empty. If I try curlRet.json[“data”] the “text” part is missing.
If I use the same syntax to extract the data from this returned value:

{
  "object": "list",
  "data": [
    {
      "id": "msg_12345",
      "object": "thread.message",
      "created_at": 1711975926,
      "assistant_id": "asst_12345",
      "thread_id": "thread_12345",
      "run_id": "run_12345",
      "role": "assistant",
      "content": [
        {
          "type": "text",
          "text": {
            "value": "Zettelkasten, Objekte, Karten, Boxen, digitale Äquivalente, Methoden, Praktiken, Tools for Thought, Notizen, Produktivität, Niklas Luhmann, Allgemeinplatzbuch, Indexkarten, Organisation, Geschichte.",
            "annotations": []
          }
        }
      ],
      "file_ids": [],
      "metadata": {}
    }
  ],
  "first_id": "msg_12345",
  "last_id": "msg_12345",
  "has_more": true
}

my variable curlRet contains “Zettelkasten, Objekte, Karten, Boxen, digitale Äquivalente, Methoden, Praktiken, Tools for Thought, Notizen, Produktivität, Niklas Luhmann, Allgemeinplatzbuch, Indexkarten, Organisation, Geschichte.”

I don’t see the difference between to two JSON strings I pass???

I’ll look into this in detail once I clear the decks here.

My first suggestion is that, when curlRet.json["data"]["content"][0]["text"][1]["value"] fails, try checking the partial results. For example, is curlRet.json["data"]["content"] what you expect?

The other place I’d double-check is the text value. Try replacing the string “Vannevar Bush…” with some other short, simple string. Does that change matters?

yes - first thing I did - curlRet.json[“data”] is the last element that will return data because “content” is missing there already.

Workaround: the following manages to parse the first json payload:

$MyDictionary=$Text.json["content"][0];
$MyString=$MyDictionary["text"]["value"];

Still working on why this is needed.

1 Like

$MyDictionary contains {} - nothing in there. And with your quick fix even the second example will not work anymore. With json[“data”][“content”][0][“text”][1][“value”] the first returns the content. Strange!

Hold on: closing in …

1 Like

OK: got it now. A problem deep, deep in the parser, in which strings lost their enclosing quotes just when those quotes were most needed.

sorry to give you so much trouble - but it sounds like you fixed it?!

Not quite fixed, but I expect to get it done today. It’s a messy issue with nested dictionaries that confuse the parser.

1 Like

Backstage build b672 should help

Great! I’ve to wait for the next final release - but that’s fine for me :wink: