Hi Guus,
Thank you for your answer. I saw you converting the record into a dictionary,
from there i was able to complete the code to convert JSON into the record structure on multiple layers.
Who wants to use this code has to take in account to initialize records with sufficient space.
program JSONTest type BasicProgram {} JSON string = "{" + " \"TransactionId\": \"abcdef\"," + " \"Content\": {" + " \"Persons\": [{" + " \"Name\": \"Niek\"," + " \"Age\": 28," + " \"DateOfBirth\": \"1987-10-20\"," + " \"Sex\": \"M\"," + " \"Hobbies\": [{" + " \"Name\": \"Hockey\"," + " \"Day\": \"Thu\"" + " }, {" + " \"Name\": \"Running\"," + " \"Day\": \"Fri\"" + " }]" + " }, {" + " \"Name\": \"Chrissy\"," + " \"Sex\": \"V\"," + " \"Hobbies\": [{" + " \"Name\": \"Make-up\"" + " }, {" + " \"Name\": \"Horseriding\"," + " \"Day\": \"Mon\"" + " }]" + " }]" + " }" + "}"; private RequestPayload requestPayload; private jsonAsDictionary dictionary{}; function main() try ServiceLib.convertFromJSON(JSON, jsonAsDictionary); setValuesRecursive(jsonAsDictionary, RequestPayload as any); onException(exception AnyException) SysLib.writeStdout(exception.message); end break boolean = true; // Put your breakpoint here end function setValuesRecursive(value dictionary, level any) for (i int from 1 to value.getKeys().getSize()) _key string = value.getKeys()[i]; _val any = value[_key]; if(_val isa dictionary) setValuesRecursive(_val, level[_key]); else if(_val isa any[]) for(j int from 1 to (_val as any[]).getSize() by 1) _arrayElement any; try _arrayElement = level[_key][j] as any; onException(exception IndexOutOfBoundsException) SysLib.writeStdout("Please initialize array with sufficient space"); SysLib.writeStdout(exception.message); SysLib.writeStdout("----------------------------------------------"); return; end setValuesRecursive(_val[j], _arrayElement); end else level[_key] = _val; end end end endendrecord RequestPayload TransactionId string; Content Content;endrecord Content Persons Person[10];endrecord Person Name string; Age int; DateOfBirth string; Sex string; Hobbies Hobby[10];endrecord Hobby Name string; Day string;end
Niek_Vandael