As Roberto pointed out the easiest way is to create a GROUP in clarion that matches your target json. Capesoft provides a website to help with that. https://capesoft.com/jfilescode
There you can paste your json example and it will generate the group and code examples for either creating a json string based on the example or how to read a json string based on the example into your Clarion code.
After fixing a couple of issues in your posted json. I came up with this:
{
"operation": "x",
"amount": "10",
"config": {
"header": "xy",
"options": [
"a",
"b",
"c"
],
"extra": true
}
}
The jfilescode created this example.
element Group,Name('element')
operation STRING(255),Name('operation')
amount STRING(255),Name('amount')
config Group,Name('config')
header_ STRING(255),Name('header')
options STRING(255),Dim(10),Name('options')
extra Byte,Name('extra | boolean')
End
End
json jsonClass
SomeSaveString StringTheory
CODE
!-- Save From Structure into StringTheory object ---
json.start()
json.SetTagCase(jf:CaseAsIs)
json.SetDontSaveBlankArrayValues(true)
element.Operation = 'x'
element.amount = 10
element.config.header_ = 'xy'
element.config.options[1] = 'a'
element.config.options[2] = 'b'
element.config.options[3] = 'a'
element.config.extra = true
json.Save(element,SomeSaveString) ! Save to a StringTheory object
! Now SomeSaveString holds your json string
You can build it up manually, but it is more work.
Something along these lines. This is untested code.
json JSONClass
jConfig &JSONClass
jOptions &JSONClass
options string(5),dim(10)
SomeSaveString StringTheory
CODE
json.Start()
json.Add('operation', 'x')
json.Add('amout', '10')
jConfig &= json.CreateCollection('config', true)
jConfig.Add('header','xy')
options[1] = 'a'
options[2] = 'b'
options[3] = 'c'
jOptions &= jConfig.AddArray('options',options)
jConfig.Add('extra',true, json:Boolean)
json.SaveString(SomeSaveString)
SomeSaveString.Trace()
The key for “sub” objects are the CreateCollection and AddArray methods.
This should get you close.