Question
· Sep 28, 2017

Switch statement from JSON record

Hi , i have a JSON record as follow {value1,value2, value3}

i want to write my switch statement in this form:

<switch> my value
<case> value1</case>
<case>value2</case>
<case>value3</case>
​</switch>

is there any possibility to extract values from JSON record and put them in a  switch statement?

thank's

Discussion (1)0
Log in or sign up to continue

{value1,value2, value3} - is incorrect in JSON

In JSON we have objects and arrays, every element in an object has name and value, while an array is a just list of values.

So, object in this format.

{
  "name": "value",
  "name2": "value2"
}

And array 

[ "value1", "value2" ]

And anyway not sure what you want to do.

Look at this article in the documentation about working with JSON in Caché.

set arr = ["value1", "value2", "value3"]
set iter = arr.%GetIterator()
write !,"<switch> my value"
while iter.%GetNext(.key, .value) {
  w !,"<case>",value,"</case>"
}
w !,"</switch>"