JSON_ARR (RPGLE)

JSON Array Implementation
Details ....

Copybooks  

'json_h.rpgle'
'json_int_h.rpgle'
'ceeapi_h.rpgle'
'libc_h.rpgle'
'arraylist_h.rpgle'
'json_c.rpgle'
'unicode_c.rpgle'

Procedures  

jsona_clearexported
Clear array
jsona_createexported
Create JSON array
jsona_disposeexported
Dispose JSON array
jsona_getArrayexported
Get array entry
jsona_getBooleanexported
Get boolean entry
jsona_getDoubleexported
Get double entry
jsona_getEntryTypeexported
Get entry type
jsona_getIntexported
Get integer entry
jsona_getLongexported
Get long entry
jsona_getObjectexported
Get object entry
jsona_getStringexported
Get string entry
jsona_isNullexported
Checks if entry is of special type null
jsona_putArrayexported
Add array entry
jsona_putBooleanexported
Add boolean entry
jsona_putDoubleexported
Add double entry
jsona_putIntexported
Add integer entry
jsona_putLongexported
Add long entry
jsona_putNullexported
Add null value entry
jsona_putObjectexported
Add JSON object entry
jsona_putStringexported
Add character entry
jsona_removeexported
Remove an entry from the array
jsona_sizeexported
Get array size
jsona_srvpgm_initexported
Service program initialization
jsona_toStringexported
String representation of the JSON array in JSON syntax

Detailed Description  

The value of a JSON object can be an array. This service program deals with such arrays. Arrays themselves can also contain arrays. An array can only contain values and arrays but no key/value pairs.

Throughout this service program is the index always 0-based. Which means that the first entry has the index 0, the second entry has the index 1 and so on.

If the index is out of the bounds of the array an escape message will be send. If a procedure for the retrieval of a special type of value is called on an entry of another type an escape message will be send too.
Author:
Mihael Schmidt
Date:
19.04.2008
Changes:
07.03.2009   —   Mihael Schmidt
Added jsona_size procedure.

27.01.2010   —   Mihael Schmidt
Added support for getting numbers with procedures jsona_getInt, jsona_getLong, jsona_getDouble no matter what the original type was (f. e. double value will be cast to int with jsona_getInt).

09.04.2011   —   Mihael Schmidt
Fixed memory management error in toString procedure.

30.04.2011   —   Mihael Schmidt
Switch from Linked List to ArrayList

20.07.2011   —   Mihael Schmidt
Remove leading plus (+) from floating point numbers when creating a string from a json array.

23.07.2011   —   Mihael Schmidt
Added jsona_isNull

Links:
http://www.json.org
http://www.rpgnextgen.com

Procedure Documentation  

jsona_clear  

voidjsona_clear(Pointer)
Removes all elements from the array.
Parameter:
Pointer   constPointer to the JSON array
Exported.

jsona_create  

Pointerjsona_create()
Creates a json array "object". Currently a linked list is used as a backend for the json array.
Return value:
PointerPointer to the JSON array
Exported.
Author:
Mihael Schmidt
Date:
19.04.2008

jsona_dispose  

voidjsona_dispose(Pointer)
Disposes a JSON array and all values it contains. All added arrays and objects are also disposed.
Parameter:
PointerPointer to the JSON array
Exported.
Author:
Mihael Schmidt
Date:
19.04.2008

jsona_getArray  

Pointerjsona_getArray(Pointer, ohne Vorzeichen)
Returns the array value of the entry.

If the entry is not of type array an escape message will be send.
Parameter:
Pointer   constPointer to the JSON array
Numerisch (ohne Vorzeichen) (10)   constIndex
Return value:
PointerPointer to the JSON array
Exported.
Author:
Mihael Schmidt
Date:
20.03.2008

jsona_getBoolean  

Booleanjsona_getBoolean(Pointer, ohne Vorzeichen)
Returns the boolean value of the entry.

If the entry is not of type boolean an escape message will be send.
Parameter:
Pointer   constPointer to the JSON array
Numerisch (ohne Vorzeichen) (10)   constIndex
Return value:
BooleanBoolean value of the entry
Exported.
Author:
Mihael Schmidt
Date:
20.03.2008

jsona_getDouble  

Fliesskommazahljsona_getDouble(Pointer, ohne Vorzeichen)
Returns the double value of the entry.

If the entry is not of type double an escape message will be send.
Parameter:
Pointer   constPointer to the JSON array
Numerisch (ohne Vorzeichen) (10)   constIndex
Return value:
Numerisch (Fliesskommazahl) (8,)Double value of the entry
Exported.
Author:
Mihael Schmidt
Date:
20.03.2008

jsona_getEntryType  

Integerjsona_getEntryType(Pointer, ohne Vorzeichen)
Returns the type of the entry.
Parameter:
Pointer   constPointer to the JSON object
Numerisch (ohne Vorzeichen) (10)   constKey
Return value:
Numerisch (Integer) (10)Entry type
Exported.

jsona_getInt  

Integerjsona_getInt(Pointer, ohne Vorzeichen)
Returns the integer value of the entry.

If the entry is not of type integer an escape message will be send.
Parameter:
Pointer   constPointer to the JSON array
Numerisch (ohne Vorzeichen) (10)   constIndex
Return value:
Numerisch (Integer) (10)Integer value of the entry
Exported.
Author:
Mihael Schmidt
Date:
20.03.2008

jsona_getLong  

Integerjsona_getLong(Pointer, ohne Vorzeichen)
Returns the long value of the entry.

If the entry is not of type long an escape message will be send.
Parameter:
Pointer   constPointer to the JSON array
Numerisch (ohne Vorzeichen) (10)   constIndex
Return value:
Numerisch (Integer) (20)Long value of the entry
Exported.
Author:
Mihael Schmidt
Date:
20.03.2008

jsona_getObject  

Pointerjsona_getObject(Pointer, ohne Vorzeichen)
Returns a pointer to the object.

If the entry is not of type object an escape message will be send.
Parameter:
Pointer   constPointer to the JSON array
Numerisch (ohne Vorzeichen) (10)   constIndex
Return value:
PointerPointer to the JSON object
Exported.
Author:
Mihael Schmidt
Date:
11.05.2008

jsona_getString  

Pointerjsona_getString(Pointer, ohne Vorzeichen)
Returns a pointer to the value of the entry for the passed key. The value is null terminated and can be processed with the %str BIF.

If the entry is not of type string an escape message will be send.
Parameter:
Pointer   constPointer to the JSON array
Numerisch (ohne Vorzeichen) (10)   constIndex
Return value:
PointerPointer to a null-terminated string
Exported.
Author:
Mihael Schmidt
Date:
20.03.2008

jsona_isNull  

Booleanjsona_isNull(Pointer, ohne Vorzeichen)
Parameter:
Pointer   constPointer to the JSON object
Numerisch (ohne Vorzeichen) (10)   constKey
Return value:
Boolean*on = entry is of type null
*off = entry is of another type
Exported.

jsona_putArray  

voidjsona_putArray(Pointer, Pointer, ohne Vorzeichen)
Adds an entry of type array.
Parameter:
Pointer   constPointer to the JSON array
Pointer   constArray
Numerisch (ohne Vorzeichen) (10)   const   optionalIndex (default: last)
Exported.
Author:
Mihael Schmidt
Date:
19.04.2008

jsona_putBoolean  

voidjsona_putBoolean(Pointer, Boolean, ohne Vorzeichen)
Adds an entry of type boolean.
Parameter:
Pointer   constPointer to the JSON array
Boolean   constValue
Numerisch (ohne Vorzeichen) (10)   const   optionalIndex (default: last)
Exported.
Author:
Mihael Schmidt
Date:
20.03.2008

jsona_putDouble  

voidjsona_putDouble(Pointer, Fliesskommazahl, ohne Vorzeichen)
Adds an entry of type double.
Parameter:
Pointer   constPointer to the JSON array
Numerisch (Fliesskommazahl) (8,)   constValue
Numerisch (ohne Vorzeichen) (10)   const   optionalIndex (default: last)
Exported.
Author:
Mihael Schmidt
Date:
20.03.2008

jsona_putInt  

voidjsona_putInt(Pointer, Integer, ohne Vorzeichen)
Adds an entry of type integer.
Parameter:
Pointer   constPointer to the JSON array
Numerisch (Integer) (10)   constValue
Numerisch (ohne Vorzeichen) (10)   const   optionalIndex (default: last)
Exported.
Author:
Mihael Schmidt
Date:
20.03.2008

jsona_putLong  

voidjsona_putLong(Pointer, Integer, ohne Vorzeichen)
Adds an entry of type long.
Parameter:
Pointer   constPointer to the JSON array
Numerisch (Integer) (20)   constValue
Numerisch (ohne Vorzeichen) (10)   const   optionalIndex (default: last)
Exported.
Author:
Mihael Schmidt
Date:
20.03.2008

jsona_putNull  

voidjsona_putNull(Pointer, ohne Vorzeichen)
Adds an entry of type null to the array.
Parameter:
Pointer   constPointer to the JSON array
Numerisch (ohne Vorzeichen) (10)   const   optionalIndex (default: last)
Exported.
Author:
Mihael Schmidt
Date:
11.05.2008

jsona_putObject  

voidjsona_putObject(Pointer, Pointer, ohne Vorzeichen)
Adds an entry of type object to the array.
Parameter:
Pointer   constPointer to the JSON array
Pointer   constPointer to the JSON object
Numerisch (ohne Vorzeichen) (10)   const   optionalIndex (default: last)
Exported.
Author:
Mihael Schmidt
Date:
11.05.2008

jsona_putString  

voidjsona_putString(Pointer, Zeichen, ohne Vorzeichen)
Adds an entry of type character.
Parameter:
Pointer   constPointer to the JSON array
Zeichen (65535)   const   variable sizeValue
Numerisch (ohne Vorzeichen) (10)   const   optionalIndex (default: last)
Exported.
Author:
Mihael Schmidt
Date:
20.03.2008

jsona_remove  

voidjsona_remove(Pointer, Integer)
Parameter:
Pointer   constPointer to the JSON array
Numerisch (Integer) (10)   constIndex of the element to be removed (0-based)
Exported.

jsona_size  

ohne Vorzeichenjsona_size(Pointer)
Returns the number of elements in the array.
Parameter:
Pointer   constPointer to the json array
Return value:
Numerisch (ohne Vorzeichen) (10)number of elements
Exported.

jsona_srvpgm_init  

voidjsona_srvpgm_init()
String formattings are preloaded.
Exported.

jsona_toString  

Pointerjsona_toString(Pointer)
Creates a null terminated string representation of the JSON array in JSON syntax.

For entries of type string double quotes and backslashes will be escaped (" => " and => \).
Parameter:
Pointer   constPointer to the JSON array
Return value:
PointerPointer to the JSON string for the passed array
Exported.
Author:
Mihael Schmidt
Date:
20.03.2008
Infos:
  The allocated memory of the returned string must be deallocated by the caller.