HWTJDEL — Delete a JSON entry

Call the HWTJDEL service to delete content from a JSON text.

Description

The HWTJDEL service deletes a name:value pair from a JSON object or a value from a JSON array. HWTJDEL accepts as input a handle representing the JSON value to be deleted, and a handle representing the containing JSON object or JSON array. The value handle can represent any of the following JSON types:
  • number or string
  • Literals true, false, or null
  • JSON object or JSON array

There are several ways to obtain the handles required to delete a given JSON value, depending on the type of value being deleted. See Examples at the end of this service for pseudo-code examples.

Environment

The requirements for the caller are:

Requirement Details
Minimum authorization: Supervisor state or problem state, any PSW key.
Dispatchable unit mode: Task or SRB.
Cross memory mode: Any PASN, any HASN, any SASN.
AMODE: 31 bit.
ASC mode: Primary or access register (AR).
Interrupt status: Enabled for I/O and external interrupts.
Locks: No locks held.
Control parameters: Control parameters must be in the primary address space and addressable by the caller.
Linkage: Standard MVS linkage conventions are used.

Programming requirements

See Syntax, linkage, and programming considerations for details about how to call the z/OS® JSON parser services in the various supported programming languages.

REXX programming considerations for the HWTJDEL service

All information for the HWTJDEL service applies for REXX requests.

Syntax

Write the call as shown in the following syntax diagram. You must code all parameters in the order shown.

Non-REXX parameters REXX parameters
CALL HWTJDEL(
        ReturnCode,
        ParserHandle,
        ObjectHandle,
        EntryValueHandle,
        DiagArea);
address hwjson "hwtjdel",
               "ReturnCode",
               "ParserHandle",
               "ObjectHandle",
               "EntryValueHandle",
               "DiagArea."

Parameters

The parameters are explained as follows:

ReturnCode
Returned parameter.
  • Type: Integer (non-REXX), character representation of an integer (REXX)
  • Length: 4 bytes (non-REXX)
Contains the return code from the service.
ParserHandle
Supplied parameter.
  • Type: Character string
  • Length: 12 bytes (non-REXX)
Specifies the JSON parser instance to be used.
ObjectHandle
Supplied parameter.
  • Type: Integer (non-REXX), character representation of an integer (REXX)
  • Length: 4 bytes (non-REXX)
Specifies an object handle representing a particular JSON object (object or array object) that contains the object or array entry to be deleted. The objectHandle value is either zero for the root object or an entry value handle (entryValueHandle) whose JSON type is HWTJ_OBJECT_TYPE or HWTJ_ARRAY_TYPE.
EntryValueHandle
Supplied parameter.
  • Type: Integer (non-REXX), character representation of an integer (REXX)
  • Length: 4 bytes (non-REXX)
Specifies a handle representing a particular entry to be deleted. The entry value handle must represent an entry contained within the JSON object or JSON array represented by ObjectHandle. If ObjectHandle represents a JSON object, EntryValueHandle must represent a member of the object. If ObjectHandle represents a JSON array, EntryValueHandle must represent an element of the array.
DiagArea (non-REXX)
DiagArea. (REXX)
Returned parameter.
  • Type: Character string (non-REXX), stem variable (REXX)
  • Length: 132 bytes (non-REXX)
A storage area provided by the caller that might contain additional diagnostic information related to the service call. It consists of a 4-byte integer reason code field and a 128-byte character string error text field.

ABEND codes

If the toolkit is unable to properly access the user-supplied parameter list, the call might result in a X'04D' ABEND with a reason code of X'000Eyyyy' for one of the following reasons:
yyyy
Reason
0000
The parameters passed by the caller are not in the primary address space.
0001
The number of parameters passed by the caller is incorrect.

Return codes

Table 1. Return codes for the HWTJDEL service
Hexadecimal return code
Equate symbol
Meaning and action
0
HWTJ_OK
Meaning: Successful completion.

Action: None.

101
HWTJ_PARSERHANDLE_INV    
Meaning: Program error. The parserHandle parameter specified on the service call is not a valid parser handle (one that was returned by the HWTJINIT service).

Action: Check for a probable coding error.

102
HWTJ_PARSERHANDLE_INUSE
Meaning: Program error. Two possible reasons can result in this return code:
  1. The parser handle is being used by another caller. Only one outstanding z/OS JSON parser service can use the same parser handle.
  2. A previous service request using this parser handle resulted in an ABEND, and the parser instance was unable to indicate that its use of the parser handle has completed.
Action: Check for a probable coding error.
  1. While all z/OS JSON parser service calls are synchronous (blocking), if more than one task, process, or thread is running simultaneously and using the same parser handle, only one is allowed access. Change the application such that only one thread attempts to use the same parser handle at a time.
  2. If the application detected an ABEND while the z/OS JSON parser was invoked, the parser instance associated with the parser handle could be permanently locked. To release the storage associated with the parser work area, issue the HWTJTERM service call with a forceOption of HWTJ_NOFORCE. If this fails with the same return code, issue another HWTJTERM service call with a forceOption of HWTJ_FORCE.
103
HWTJ_INACCESSIBLE_PARM
Meaning: Program error. The application passed an input or output parameter which was inaccessible by the parser. See General programming considerations for details about z/OS JSON parser recovery processing.

Action: Check for a probable coding error. Likely, the recovery of the caller detected this return code as a result of the parser abnormally ending with a X'0C4' system ABEND. Check the diagArea for an explanation as to which parameter was attempting to be accessed when the parser service calls abnormally ended. See General programming considerations for details about actions to consider for this return code.

104
HWTJ_HANDLE_INV
Meaning: Program error. The value specified for the objectHandle or entryValueHandle parameter is not valid.

Action: Check for a probable coding error. (For example, uninitialized handle or a reference to a deleted entry.)

105
HWTJ_HANDLE_TYPE_ERROR
Meaning: Program error. The specified objectHandle does not represent an object or array object (JSON type of HWTJ_OBJECT_TYPE or HWTJ_ARRAY_TYPE).

Action: Check for a probable coding error. Specify a handle that represents a JSON object or JSON array.

901
HWTJ_JDEL_ENTRY_NOTE_FOUND
Meaning: Program error. The specified entryValueHandle does not represent an entry contained within the object specified by objectHandle

Action: Check for a probable coding error.

F01
HWTJ_INTERRUPT_STATUS_INV
Meaning: Program error. The calling program is disabled. The system rejects the service request.

Action: Check the calling program for a probable coding error.

F02
HWTJ_LOCKS_HELD
Meaning: Program error. The calling program is holding one or more locks. The system rejects the service request.

Action: Check the calling program for a probable coding error.

F03
HWTJ_UNSUPPORTED_RELEASE
Meaning: The operating system level does not support this service. The system rejects the service request.

Action: Remove the calling program from this system, install it on a system that supports z/OS JSON parser services, and run the calling program again.

FFF
HWTJ_UNEXPECTED_ERROR
Meaning: System error. The service encountered an unexpected error. The system rejects the service call.

Action: Search problem reporting databases for a fix for the problem. If no fix exists, contact the IBM Support Center.

Examples

The following pseudo-code examples demonstrate several uses of HWTJDEL.

Example 1:

Given the following JSON text:


{  
   "foo":{  
      "mood":"happy",
      "color":"red",
      "bling":"baz"
   },
   "bar":[  "bag", 3, true]
}

To delete the "mood" entry from the "foo" object, first call HWTJSRCH to obtain a handle to the "foo" object.


objectName = "foo"  
rootObject = 0         /* search the root object */
startingHandle = 0  /* start with the first member */

HWTJSRCH ( 
    returnCode,
    parserHandle,
    HWTJ_SEARCHTYPE_GLOBAL,
    objectName,
    length(objectName),
    rootObject,
    startingHandle,
    targetObjectHandle,
    DiagArea
);

The output handle (targetObjectHandle) can then be used on a subsequent call to HWTJSRCH to find the "mood" entry.


entryName = "mood"

HWTJSRCH ( 
    returnCode,
    parserHandle,
    HWTJ_SEARCHTYPE_OBJECT,
    entryName,
    length(entryName),
    targetObjectHandle,
    startingHandle,
    targetEntryHandle,
    diagArea
);

Having obtained the required targetObjectHandle and targetEntryHandle, a call to HWTJDEL would look similar to this:


HWTJDEL(
    returnCode,
    parserHandle,
    targetObjectHandle,
    targetEntryHandle,
    diagArea
);

A subsequent call to HWTJSERI would return a JSON text string reflecting the delete operation.


{  
   "foo":{  
      "color":"red",
      "bling":"baz"
   },
   "bar":[  "bag", 3, true]
}

Example 2:

Deleting an element from a JSON array would require a slightly different sequence of operations.

Given the following JSON text:


{  
   "bar":[  "bag", 3, true, {"a": "somewhere"} ],
   "bling": "blam",
   "pi": 3.14159
}

To delete the fourth entry (the object with a single entry named "a") from the "bar" array , first call HWTJSRCH to obtain a handle to the "bar" array.


arrayName = "bar"
rootObject = 0       /* Search the root */
startingHandle = 0 /* Start at the first member */
targetArrayHandle = 0

HWTJSRCH (
    returnCode,
    parserHandle,
    HWTJ_SEARCHTYPE_GLOBAL,
    arrayName,
    length(arrayName),
    rootObject,
    startHandle,
    targetArrayHandle,
    DiagArea
);

The output handle (targetArrayHandle) can then be used on a subsequent call to HWTJGAEN to retrieve a handle to the fourth array value.


entryIndex = 3 /* Note that array entries are zero-indexed */ 

HWTJGAEN (
    returnCode,
    parserHandle,
    targetArrayHandle,
    entryIndex,
    targetEntryHandle,
    diagArea
);

Having obtained the required targetArrayHandle and targetEntryHandle, a call to HWTJDEL would look similar to this:


HWTJDEL(
    returnCode,
    parserHandle,
    targetArrayHandle,
    targetEntryHandle,
    diagArea
);

A subsequent call to the HWTJSERI service would return a JSON text string reflecting the delete operation.

{  
   "bar":[  "bag", 3, true ],
   "bling": "blam",
   "pi": 3.14159
}