AI Zone Admin Forum Add your forum

NEWS: Chatbots.org survey on 3000 US and UK consumers shows it is time for chatbot integration in customer service!read more..

json direct access
 
 

Hi, here a simplfied version of my problem:

I have a json string array and want to change an excisiting element of the array:

$$jsonObject = ^jsoncreate(permanent array)
 ^
jsonarrayinsert(permanent $$jsonObject ^"This is a test sentence.")
 ^
jsonarrayinsert(permanent $$jsonObject ^"This is a second sentence.")

 $
$jsonObject[1] = ^"This is a changed sentence"
 
Output: ^jsonwrite($$jsonObject

But the code leans to the following outout, the value is not changed.

Output: [“This is a test sentence.”, “This is a second sentence.”]

What makes it even weirder, if I place the array inside an json object and use this object to access and change the value, the result is different, but wrong, too

$$jsonObject = ^jsoncreate(permanent array)
 ^
jsonarrayinsert(permanent $$jsonObject ^"This is a test sentence.")
 ^
jsonarrayinsert(permanent $$jsonObject ^"This is a second sentence.")


 $
$jsonWrapper = ^jsoncreate(permanent object)
 ^
jsonobjectinsert(permanent $$jsonWrapper array $$jsonObject)
 $
$jsonWrapper.array[1] = ^"This is a changed sentence"
 
Output: ^jsonwrite($$jsonObject

Output: [“1]”: “This is a changed sentence”]

Is this a bug or am I missing something?
Is there a workaround for this?

 

 
  [ # 1 ]

Currently you are not allowed to specify $x[1] = y because the system is protecting the order of contents in the array and you might name an index that does not exist. You can remove your [1] and then add new value, but the index will be changed. I can probably fix this at some point. You could, in the meantime, use a json object whose keys are the numbers of your indices.

 

 
  login or register to react