Experimenting with JSON-like storage on places it should not exist.
Most of the codebase is compatible with cobol85, the oldest cobol standard in GnuCOBOL which is forward compatible.
However, some specific programs need more advanced features (mainly recursive) so they are compiled with ibm (which can also compile everything). This may change in the future, as an older cobol version with recursive support may be chosen or the dependency on recursive may be dropped altogether.
While some compilers have easier routes, this is the standard way to include the library (in gnucobol for example):
cobc -x yourprogram.cob uncobol/*.cobYou can also type out each file (utils_removeLastDot, uncobol_edit, obj_set...), but you will probably have to change that every time you want to update the library (which can be done by just cloning a newer version) as the library's structure may change in the future.
From tests/test_all.cob
* DATA DIVISION.
* local-storage section, working-storage section or linkage section
01 storage.
02 stored-item OCCURS 20 TIMES.
03 item-name PIC X(10).
03 item-value PIC X(20).
03 parent PIC 9(2).
03 children OCCURS 5 TIMES.
04 child-name PIC X(10).
04 child-num PIC 9(2).
01 target_object PIC X(255).
01 object_value PIC X(20).
01 got-value PIC X(20).
* PROCEDURE DIVISION.
* Initialize
CALL "obj_init" USING BY REFERENCE storage.
* Create a simple structure:
* main: {
* a: {
* c: "hello"
* }
* }
MOVE "main.a.c" TO target_object.
MOVE "hello" TO object_value.
CALL "obj_set" USING BY REFERENCE storage target_object
object_value.
* Get value of `main.a.c`
CALL "obj_get" USING by reference storage target_object
got-value.
DISPLAY got-value.
* Expected: hello
* Delete only main.a.c (not main.a as a whole)
CALL "obj_del" USING BY REFERENCE storage target_object.
* Check if main.a.c exists
MOVE low-value TO got-value.
CALL "obj_get" USING BY REFERENCE storage target_object
got-value.
DISPLAY got-value.
* ^ Expected: null
STOP RUN.* DATA DIVISION.
* local-storage section, working-storage section or linkage section
01 storage.
02 stored-item OCCURS 20 TIMES.
03 item-name PIC X(10).
03 item-value PIC X(20).
03 parent PIC 9(2).
03 children OCCURS 5 TIMES.
04 child-name PIC X(10).
04 child-num PIC 9(2).
01 start_at PIC 9(2).
01 start_level PIC 9(2).
01 edit_string PIC X(255) value spaces.
* PROCEDURE DIVISION.
* ...initialize and edit the storage...
CALL "obj_toJSON" USING BY REFERENCE storage start_at
start_level edit_string.
DISPLAY edit_string.
* ^ Expected: {...}