<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to Setting array values with JSON Utilities SL</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/3884bc3ce7/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/Engineering/thread/3884bc3ce7/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/Engineering/thread/3884bc3ce7/</id><updated>2024-05-23T14:42:42.454000Z</updated><subtitle>Recent posts to Setting array values with JSON Utilities SL</subtitle><entry><title>Setting array values with JSON Utilities SL</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/3884bc3ce7/?limit=25#a0af" rel="alternate"/><published>2024-05-23T14:42:42.454000Z</published><updated>2024-05-23T14:42:42.454000Z</updated><author><name>corriibme</name><uri>https://forge.codesys.com/u/corriibme/</uri></author><id>https://forge.codesys.com01256c11c90c846d6d91c5b51581d323610adfbd</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;It turns out that you can build JSON structures without ever calling the JSONBuilder function block directly. Instead, create a pointer to JSON.JSONData and invoke the necessary methods on its dereference. The parent object has a parent index of -1 (and an index of 0). EVERY other item (including keys, values, empty arrays and sub-objects) created by the setX methods needs the index to increase by 1.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Setting array values with JSON Utilities SL</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/3884bc3ce7/?limit=25#337f" rel="alternate"/><published>2024-05-12T14:42:36.363000Z</published><updated>2024-05-12T14:42:36.363000Z</updated><author><name>corriibme</name><uri>https://forge.codesys.com/u/corriibme/</uri></author><id>https://forge.codesys.com90c2cf3763f2e662e449d589de6b0b5ccd80387d</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;I have been trying to set an array value to a JSON structure of this form:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;{"key": [1,2,3,4]}&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;While I have been able to create the key and set its value to an empty array, I've not had any luck in putting any value in that array.&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="nt"&gt;objindex&lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;fb_JBuilder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;SetKeyWithArray&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Key6"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;diParentIndex&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;diRootIndex&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="nt"&gt;objindex2&lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;fb_JBuilder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;SetValue&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;value&lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;iValue2&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;diParentIndex&lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;objindex&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;code&gt;iValue2: ARRAY[0..3] OF INT:= [1,2,3,4];&lt;/code&gt;&lt;br/&gt;
The two lines of code above produce {"key6": []} . The second line essentially has no effect.&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>