# Fill element of json

**URL:** <https://clarionhub.com/t/fill-element-of-json/7423>\
**Category:** questions\
**Tags:** json\
**Created:** [August 28, 2024, 5:46pm UTC](https://clarionhub.com/t/fill-element-of-json/7423 "2024-08-28T17:46:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![PoulJ](https://clarionhub.com/user_avatar/clarionhub.com/poulj/32/798_2.png) [@PoulJ](https://clarionhub.com/u/PoulJ)\
**Post date:** [August 28, 2024, 5:46pm UTC](https://clarionhub.com/t/fill-element-of-json/7423/1 "2024-08-28T17:46:35Z")

</div>

Hi,

I need to create a json collection to submit to a webserver and has used Capesoft jFilesCode to create the structure.

Below you can se the json structure, the data declaration and the code I have that works.

What I am missing is filling one element of the subqueue "parcels".  
I have a brainfart and cannot get any code to work.

Any ideas?

tia  
/Poul

```auto
json:
{{
  "product_code": "DAO_STS",
  "service_codes": "EMAIL_NT,SMS_NT",
  "sender": {{
    "name": "A-fotograf",
    "address1": "Tygestrupvej 17",
    "zipcode": "4180",
    "city": "Sorø",
    "country_code": "DK",
  },
  "parcels": [
    {{
      "weight": 249
    }
  ],
  "reference": "Ordre nr.: 126126"
}

data embed:
element Group,Name('element'),PRE(elpre)
product_code STRING(255),Name('product_code| opt')
service_codes STRING(255),Name('service_codes| opt')
sender Group,Name('sender')
name STRING(255),Name('name')
address1 STRING(255),Name('address1')
zipcode STRING(255),Name('zipcode')
city STRING(255),Name('city')
country_code STRING(255),Name('country_code')
                        End
parcels &parcelsQueueType,Name('parcels| opt | queue')
reference STRING(255),Name('reference| opt')
                    End

parcelsQueueType Queue,Type,Name('parcels')
weight Real,Name('weight')
                    End

Json JSONClass
str StringTheory

code:
    json.start()
    json.SetTagCase(jf:CaseAsIs)
    json.SetDontSaveBlanks(true)
    json.SetDontSaveBlankArrays(true)
    json.SetDontSaveBlankArrayValues(true)
    json.SetDontSaveBlankGroups(true)
    elpre:product_code = DAO_product_code
    elpre:service_codes = DAO_service_codes
    elpre:sender.name = DAO_afs_name
    elpre:sender.address1 = DAO_afs_addr1
    elpre:sender.zipcode = DAO_afs_zipcode
    elpre:sender.city = DAO_afs_city
    elpre:sender.country_code = 'DK'
    elpre:reference = CLIP('Ordre nr.: ' & clip(FOTo:ID) )    
     
!--> missing parcels.weight

        json.Save(element,str) ! Save to a StringTheory object
        json.DisposeGroup(element) !Optional Safe Tidy up of nested pointers  

```

---

<div class="post-metadata">

**Author:** ![Rick\_UpperPark](https://clarionhub.com/user_avatar/clarionhub.com/rick_upperpark/32/346_2.png) [@Rick\_UpperPark](https://clarionhub.com/u/Rick_UpperPark)\
**Post date:** [August 28, 2024, 9:37pm UTC](https://clarionhub.com/t/fill-element-of-json/7423/2 "2024-08-28T21:37:33Z")

</div>

If I understand what you are asking …

```auto
    json.start()
    json.SetTagCase(jf:CaseAsIs)
    json.SetDontSaveBlanks(true)
    json.SetDontSaveBlankArrays(true)
    json.SetDontSaveBlankArrayValues(true)
    json.SetDontSaveBlankGroups(true)
clear(elpre) !Force of habit
    elpre:product_code = DAO_product_code
    elpre:service_codes = DAO_service_codes
    elpre:sender.name = DAO_afs_name
    elpre:sender.address1 = DAO_afs_addr1
    elpre:sender.zipcode = DAO_afs_zipcode
    elpre:sender.city = DAO_afs_city
    elpre:sender.country_code = 'DK'
    elpre:reference = CLIP('Ordre nr.: ' & clip(FOTo:ID) )    
     
!Add these lines, plus additional ADD calls on the parcles queue
element.parcels &= new(parcelsQueueType)
element.parcels.weight = 249
add(element.parcels)

        json.Save(element,str) ! Save to a StringTheory object
        json.DisposeGroup(element) !Optional Safe Tidy up of nested pointers

```

---

<div class="post-metadata">

**Author:** ![PoulJ](https://clarionhub.com/user_avatar/clarionhub.com/poulj/32/798_2.png) [@PoulJ](https://clarionhub.com/u/PoulJ)\
**Post date:** [August 29, 2024, 5:24am UTC](https://clarionhub.com/t/fill-element-of-json/7423/3 "2024-08-29T05:24:36Z")

</div>

Thanks Rick,

That is what I need, but the suggested code gives these errors:

Unknown variable type  
Field not found: WEIGHT

---

<div class="post-metadata">

**Author:** ![Rick\_UpperPark](https://clarionhub.com/user_avatar/clarionhub.com/rick_upperpark/32/346_2.png) [@Rick\_UpperPark](https://clarionhub.com/u/Rick_UpperPark)\
**Post date:** [August 29, 2024, 2:59pm UTC](https://clarionhub.com/t/fill-element-of-json/7423/4 "2024-08-29T14:59:50Z")

</div>

I edited my answer and changed the elpre:parcels usage to element.parcels.  
I never use prefix:queuefield syntax, but wanted to follow the format you started with.  
I use dot notation. So instead of elpre:field, I’d use element.field

---

<div class="post-metadata">

**Author:** ![PoulJ](https://clarionhub.com/user_avatar/clarionhub.com/poulj/32/798_2.png) [@PoulJ](https://clarionhub.com/u/PoulJ)\
**Post date:** [August 29, 2024, 3:31pm UTC](https://clarionhub.com/t/fill-element-of-json/7423/5 "2024-08-29T15:31:36Z")

</div>

Thanks Rick - that did it 🙂

The reason I am using prefix:queuefield is caused by the fact that I could not get Code Completion to work without it, so I added the prefix.  
Now CC works without it, go figure…
