JSON   (RPGLE)

JSON Service program
More ....

Procedures  [top]

disposeEntryValue  
Dealloc entry value
escapeLastToken exported
Escape characters
getJSONEntry  
Get entry by key
isJSONImpl  
Check for JSON object
json_abortIteration exported
Abort iteration
json_clear exported
Clear JSON object
json_contains exported
Contains key
json_create exported
Create JSON Object
json_dispose exported
Deallocate JSON object
json_get exported
Get entry
json_getArray exported
Get array entry
json_getBoolean exported
Get boolean entry
json_getDouble exported
Get double entry
json_getInt exported
Get integer entry
json_getLong exported
Get long entry
json_getNext exported
Get next entry
json_getObject exported
Get object entry
json_getString exported
Get string entry
json_isEmpty exported
Is JSON object empty
json_putArray exported
Add array entry
json_putBoolean exported
Add boolean entry
json_putDouble exported
Add double entry
json_putInt exported
Add integer entry
json_putLong exported
Add long entry
json_putNull exported
Add null value entry
json_putObject exported
Add JSON object entry
json_putString exported
Add character entry
json_remove exported
Remove entry
json_size exported
Count JSON object entries
json_toString exported
String representation of the JSON object in JSON syntax
sendDiagnosticMessage exported
Send diagnostic message
sendEscapeMessage exported
Send escape message

Copybooks  [top]

JSON_H
JSON_INT_H
CEEAPI_H
LLIST_H
JSON_C

Detailed Description  [top]

From the main web site:

JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. It is based on a subset of the JavaScript Programming Language, Standard ECMA-262 3rd Edition - December 1999. JSON is a text format that is completely language independent but uses conventions that are familiar to programmers of the C-family of languages, including C, C++, C#, Java, JavaScript, Perl, Python, and many others. These properties make JSON an ideal data-interchange language.

JSON is built on two structures:

These are universal data structures. Virtually all modern programming languages support them in one form or another. It makes sense that a data format that is interchangable with programming languages also be based on these structures.

In JSON, they take on these forms:

An object is an unordered set of name/value pairs. An object begins with { (left brace) and ends with } (right brace). Each name is followed by : (colon) and the name/value pairs are separated by , (comma).

Concerning this implementation:

The pointer to the JSON object will be check on every procedure call. If the pointer does not point to a JSON object an escape message will be send to the next level of the call stack.

If the JSON obect is queried for an entry of a specific type and the type does not match with the expectation of the procedure an escape message will be send to the next level of the call stack.

All the allocated memory of the JSON object and its entries is managed by this service program and will be freed with the call of the procedure dispose. No manual deallocation must be done.
Author:
Mihael Schmidt
Date:
20.03.2008
Links:
JSON


Procedure Documentation  [top]

disposeEntryValue  [top]

disposeEntryValue ( Pointer )
The value of an entry is deallocated. If the entry is of type object or array it must be disposed.
Parameters:
Pointer Pointer to an entry
Author:
Mihael Schmidt
Date:
14.05.2008

escapeLastToken  [top]

escapeLastToken ( Pointer )
Double quotes and backslashes must be escape in string values to comply to the JSON specs.

The last element of the token list will be checked for characters which need to be escaped.
Parameters:
Pointer Pointer to token list
Exported.
Author:
Mihael Schmidt
Date:
20.03.2008

getJSONEntry  [top]

Pointer getJSONEntry ( Pointer, Pointer, Unsigned )
Returns a pointer to the entry data structure for the passed key.
Parameters:
Pointer Pointer to the JSON object
Pointer Pointer to the key
Numeric (Unsigned) (10) Key length
Return value:
Pointer Pointer to the entry or *null if no such entry exists in this JSON object.

isJSONImpl  [top]

isJSONImpl ( Pointer )
Checks if the passed pointer points to a JSON object.

If the pointer does not point to a JSON object and escape message will be send to the next entry in the call stack.
Parameters:
Pointer Pointer to the JSON object
Author:
Mihael Schmidt
Date:
20.03.2008

json_abortIteration  [top]

json_abortIteration ( Pointer )
Resets the iteration of the JSON Object.
Parameters:
Pointer Pointer to the JSON object
Exported.
Author:
Mihael Schmidt
Date:
20.03.2008

json_clear  [top]

json_clear ( Pointer )
Removes all entries from the JSON object.
Parameters:
Pointer Pointer to the JSON object
Exported.
Author:
Mihael Schmidt
Date:
20.03.2008

json_contains  [top]

Boolean json_contains ( Pointer, Character )
Checks if the JSON object contains an entry with the passed key.
Parameters:
Pointer Pointer to the JSON object
Character (65535) Entry key
Return value:
Boolean *on = JSON object contains key
*off = JSON object does not contain key
Exported.
Author:
Mihael Schmidt
Date:
20.03.2008

json_create  [top]

Pointer json_create ( )
Creates a JSON Object.

The memory allocated for this object must be deallocated with the dispose procedure when finished.
Return value:
Pointer Pointer to the JSON object
Exported.
Author:
Mihael Schmidt
Date:
20.03.2008

json_dispose  [top]

json_dispose ( Pointer )
The memory for the JSON Object will be deallocated and the passed pointer will be set to *null.
Parameters:
Pointer Pointer to the JSON object
Exported.
Author:
Mihael Schmidt
Date:
20.03.2008

json_get  [top]

Pointer json_get ( Pointer, Character )
Gets the value of entry in the JSON object as a string.

The return value is a pointer to a null terminated string so that it can be easily processed with the %str BIF.

The memory for the return value was allocated will be managed by the JSON object and will be disposed with the dispose procedure. The calling program does not need to deallocate the the memory by itself.
Parameters:
Pointer Pointer to the JSON object
Character (65535) Key
Return value:
Pointer Pointer to a null terminated string or *null if JSON object does not contain the passed key
Exported.
Author:
Mihael Schmidt
Date:
20.03.2008

json_getArray  [top]

Pointer json_getArray ( Pointer, Character )
Returns the array value of the entry.

If the entry is not of type array an escape message will be send.
Parameters:
Pointer Pointer to the JSON object
Character (65535) Key
Return value:
Pointer Pointer to the JSON array
Exported.
Author:
Mihael Schmidt
Date:
20.03.2008

json_getBoolean  [top]

Boolean json_getBoolean ( Pointer, Character )
Returns the boolean value of the entry.

If the entry is not of type boolean an escape message will be send.
Parameters:
Pointer Pointer to the JSON object
Character (65535) Key
Return value:
Boolean Boolean value of the entry
Exported.
Author:
Mihael Schmidt
Date:
20.03.2008

json_getDouble  [top]

Float json_getDouble ( Pointer, Character )
Returns the double value of the entry.

If the entry is not of type double an escape message will be send.
Parameters:
Pointer Pointer to the JSON object
Character (65535) Key
Return value:
Numeric (Float) (8,) Double value of the entry
Exported.
Author:
Mihael Schmidt
Date:
20.03.2008

json_getInt  [top]

Integer json_getInt ( Pointer, Character )
Returns the integer value of the entry.

If the entry is not of type integer an escape message will be send.
Parameters:
Pointer Pointer to the JSON object
Character (65535) Key
Return value:
Numeric (Integer) (10) Integer value of the entry
Exported.
Author:
Mihael Schmidt
Date:
20.03.2008

json_getLong  [top]

Integer json_getLong ( Pointer, Character )
Returns the long value of the entry.

If the entry is not of type long an escape message will be send.
Parameters:
Pointer Pointer to the JSON object
Character (65535) Key
Return value:
Numeric (Integer) (20) Long value of the entry
Exported.
Author:
Mihael Schmidt
Date:
20.03.2008

json_getNext  [top]

Pointer json_getNext ( Pointer )
Iterates through all JSON entries and returns a pointer to the key of the next entry.

If the iteration ends with the last key *null will be returned.

If the iteration is aborted the calling program should use the abortIteration procedure to reset the iteration.
Parameters:
Pointer Pointer to the JSON object
Return value:
Pointer Pointer to the key of the next entry or *null if there are no more entries
Exported.
Author:
Mihael Schmidt
Date:
20.03.2008

json_getObject  [top]

Pointer json_getObject ( Pointer, Character )
Returns a pointer to the object.

If the entry is not of type object an escape message will be send.
Parameters:
Pointer Pointer to the JSON array
Character (65535) Index
Return value:
Pointer Pointer to the JSON object
Exported.
Author:
Mihael Schmidt
Date:
11.05.2008

json_getString  [top]

Pointer json_getString ( Pointer, Character )
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.
Parameters:
Pointer Pointer to the JSON object
Character (65535) Key
Return value:
Pointer Pointer to a null-terminated string
Exported.
Author:
Mihael Schmidt
Date:
20.03.2008

json_isEmpty  [top]

Boolean json_isEmpty ( Pointer )
Checks if the JSON object contains no entries at all.
Parameters:
Pointer Pointer to the JSON object
Return value:
Boolean *on = JSON object is empty
*off = JSON object is not empty
Exported.
Author:
Mihael Schmidt
Date:
20.03.2008

json_putArray  [top]

json_putArray ( Pointer, Character, Pointer )
Adds an entry of type array.
Parameters:
Pointer Pointer to the JSON object
Character (65535) Key
Pointer Array
Exported.
Author:
Mihael Schmidt
Date:
19.04.2008

json_putBoolean  [top]

json_putBoolean ( Pointer, Character, Boolean )
Adds an entry of type boolean.
Parameters:
Pointer Pointer to the JSON object
Character (65535) Key
Boolean Value
Exported.
Author:
Mihael Schmidt
Date:
20.03.2008

json_putDouble  [top]

json_putDouble ( Pointer, Character, Float )
Adds an entry of type double.
Parameters:
Pointer Pointer to the JSON object
Character (65535) Key
Numeric (Float) (8,) Value
Exported.
Author:
Mihael Schmidt
Date:
20.03.2008

json_putInt  [top]

json_putInt ( Pointer, Character, Integer )
Adds an entry of type integer.
Parameters:
Pointer Pointer to the JSON object
Character (65535) Key
Numeric (Integer) (10) Value
Exported.
Author:
Mihael Schmidt
Date:
20.03.2008

json_putLong  [top]

json_putLong ( Pointer, Character, Integer )
Adds an entry of type long.
Parameters:
Pointer Pointer to the JSON object
Character (65535) Key
Numeric (Integer) (20) Value
Exported.
Author:
Mihael Schmidt
Date:
20.03.2008

json_putNull  [top]

json_putNull ( Pointer, Character )
Adds an entry of type null to the array.
Parameters:
Pointer Pointer to the JSON array
Character (65535) Key
Exported.
Author:
Mihael Schmidt
Date:
11.05.2008

json_putObject  [top]

json_putObject ( Pointer, Character, Pointer )
Adds an entry of type object to the array.
Parameters:
Pointer Pointer to the JSON array
Character (65535) Key
Pointer Pointer to the JSON object
Exported.
Author:
Mihael Schmidt
Date:
11.05.2008

json_putString  [top]

json_putString ( Pointer, Character, Character )
Adds an entry of type character.
Parameters:
Pointer Pointer to the JSON object
Character (65535) Key
Character (65535) Value
Exported.
Author:
Mihael Schmidt
Date:
20.03.2008

json_remove  [top]

json_remove ( Pointer, Character )
If the JSON entry contains such an entry it will be removed.
Parameters:
Pointer Pointer to the JSON object
Character (65535) Entry key
Exported.
Author:
Mihael Schmidt
Date:
20.03.2008

json_size  [top]

Integer json_size ( Pointer )
Returns the number of entries in the JSON object. The keys of the entries are counted. If the JSON object contains arrays the elements of the arrays are ignored.
Parameters:
Pointer Pointer to the JSON object
Return value:
Numeric (Integer) (10) number of entries in the JSON object
Exported.
Author:
Mihael Schmidt
Date:
20.03.2008

json_toString  [top]

Pointer json_toString ( Pointer )
Creates a null terminated string representation of the JSON object in JSON syntax.

For entries of type string double quotes and backslashes will be escaped (" => \" and \ => \\).
Parameters:
Pointer Pointer to the JSON object
Exported.
Author:
Mihael Schmidt
Date:
20.03.2008

sendDiagnosticMessage  [top]

sendDiagnosticMessage ( Character )
Sends a diagnostic message to the call stack (one level above this one).
Parameters:
Character (200) Message
Exported.
Author:
Mihael Schmidt
Date:
07.03.2009

sendEscapeMessage  [top]

sendEscapeMessage ( Integer )
A wrapper for the i5/OS API QMHSNDPM.
Parameters:
Numeric (Integer) (10) Message id
Exported.
Author:
Mihael Schmidt
Date:
20.03.2008