Sabit Issakhan · Apr 28, 2021

How parse Library.ListOfObjects to JSON

Hello! I have a question how to parse Library.ListOfObjects to JSON

I send post data like this from client using rest and want parse "templates", after save "codeForm","codeName" in database

    "whoIs": "",
    "templates": [{
            "codeForm": "FORM_FIOGROUP",
            "codeName": "operationDate",
            "orderNumber": "1",
            "codeFormat": "YYYY-MM-DD",
            "header": "DATE",
            "dbfFormatType": "Date",
            "dbfFormatLength": "8",
            "valueFrom": "Payment"
        }, {
            "codeForm": "FORM_FIOGROUP",
            "codeName": "rrn",
            "orderNumber": "2",
            "codeFormat": "String",
            "header": "REFERENCE",
            "dbfFormatType": "String",
            "dbfFormatLength": "25",
            "valueFrom": "Payment"

I use this way, but it doesn't work:

set content = %request.Content

set iter = content.templates.$getIterator()

while iter.$getNext(.key, .value) {


Product version: Ensemble 2016.1
3 0 4 69
Log in or sign up to continue


What is the error message?

By default Content is a stream. Try converting it into dynamic object

set content = {}.$fromJSON(%request.Content)

I solve error with this code:

set content = %request.Content
Set whoIs = content.whoIs 
Set templates = content.templates 
Set templateCount = templates.Count() 
for i=1:1:templateCount {
Set row = templates.GetAt(i) Set codeForm = row.codeForm
Set codeName = row.codeName
Set orderNumber = row.orderNumber
Set codeFormat = row.codeFormat
Set headerXLS = row.headerXLS
Set headerDBF = row.headerDBF
Set dbfFormatType = row.dbfFormatType
Set dbfFormatLength = row.dbfFormatLength
Set valueFrom = row.valueFrom

You are using a 5 year old version of Ensemble that is using an experimental release of JSON support with classes named %Library.AbstractObject, %Library.Object and %Library.Array.  When you upgrade to any version after 2016.1 you will find the JSON support classes are now named %Library.DynamicAbstractObject, %Library.DynamicObject and %Library.DynamicArray.  All of the method names will change because support for system methods with names that start with $ has been removed.  Method names like  $getIterator, $fromJSON and $getNext will become %GetIterator, %FromJSON and %GetNext.  Other than the extensive name changes, most of features of the experimental JSON classes has remained unchanged.

There are additional new features added during future releases. For example, the ObjectScript language will accept JSON object and array constructor syntax as part of the ObjectScript expression syntax.  If an element which is part of an object/array constructor inside an ObectScript program is enclosed in round parentheses then that element is evaluated using ObjectScript expression syntax instead using JSON literal syntax.  There will also be some additional ways to control the conversions between JSON types and ObjectScript types.