2.5.2.2.3 Conversion Examples:
Example 2-19 VIEW Description File
VIEW empname
#TYPE CNAME FBNAME COUNT FLAG SIZE NULL
char fname EMP_FNAME 1 - 25 -
char minit EMP_MINIT 1 - 1 -
char lname EMP LNAME 1 - 25 -
END
VIEW emp
struct empname ename 1 - - -
unsignedlong id EMP_ID 1 - - -
long ssn EMP_SSN 1 - - -
double salaryhist EMP_SAL 10 - - -
END
Corresponding header file after compilation
Example 2-20 Compilation
struct empname {
char fname[25];
char minit;
char lname[25];
};
struct emp {
struct empname ename;
unsigned long id;
long ssn;
double salaryhist[10];
}
Example 2-21 JSON Content
{
"ename":
{
"EMP_FNAME":"John",
"EMP_MINIT":"R",
"EMP_LNAME":"Smith"
},
"EMP_ID":1234,
"EMP_SSN":123456789,
"EMP_SAL":
[10000.0,
11000.0,
12000.0,
13000.0,
14000.0,
15000.0,
16000.0,
17000.0,
18000.0,
19000.0]
}
}
Without FBNAME
(names specified in the view file), the content is represented using the CNAME
values. Since nesting cannot be expressed without field names because the field name is also the subtype name for the nested view, only structures with 1 level are represented.
For example:
Example 2-22 VIEW Description
VIEW empname
#TYPE CNAME FBNAME COUNT FLAG SIZE NULL
char fname - 1 - 25 -
char minit - 1 - 1 -
char lname - 1 - 25 -
END
Corresponding header file after compilation
Example 2-23 Compilation
struct empname {
char fname[25];
char minit;
char lname[25];
};
Example 2-24 JSON Content Example
{
"fname":"John",
"minit":"R",
"lname":"Smith"
}
Example 2-25 Field Table
#name rel-number type flags comment
BIKES 1 fml32 -
COLOR 2 string -
CURSERIALNO 3 string -
INSTOCK 4 string -
NAME 5 string -
ORDERDATE 6 string -
PRICE 7 float -
SERIALNO 8 string -
SIZE 9 long -
SKU 10 string -
TYPE 11 string -
Example 2-26 JSON Content
"BIKES":
[
{"COLOR":"BLUE",
"CURSERIALNO":"AZ123",
"INSTOCK":"Y",
"NAME":"CUTTER",
"ORDERDATE":"11/03/2012",
"PRICE":1234.55,
"SERIALNO":"123456",
"SIZE":52,
"SKU":"CU521234",
"TYPE":"ROAD"},
{"COLOR":"RED",
"CURSERIALNO":"BZ123",
"INSTOCK":"Y",
"NAME":"ROCKGLIDER",
"ORDERDATE":"11/06/2012",
"PRICE":1455.55,
"SERIALNO":"123457",
"SIZE":16,
"SKU":"RG161234",
"TYPE":"MTB"},
]
}
}
Record example.
Example 2-27 COBOL copybook
01 myRecord.
05 name occurs 1 times PIC X(10).
05 num occurs 1 times PIC S9(9) COMP-5.
05 subgroup occurs 1 times.
10 long1 PIC S9(9) COMP-5.
10 string1 PIC X(19).
Example 2-28 Result
{
"name": "aaa",
"num": 1000,
"subgroup": {
"long1": 3000,
"string1": "wwww"
}
}
Parent topic: JSON Data Mapping