Skip to content

Commit

Permalink
RedfishPkg/JsonLib: Add JSON delete object function
Browse files Browse the repository at this point in the history
To support the deletion on a specified JSON object.

Signed-off-by: Abner Chang <[email protected]>
Cc: Nickle Wang <[email protected]>
Cc: Igor Kulchytskyy <[email protected]>
Reviewed-by: Nickle Wang <[email protected]>
  • Loading branch information
changab authored and mergify[bot] committed Jan 16, 2024
1 parent 8f6d343 commit 9971b99
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
17 changes: 17 additions & 0 deletions RedfishPkg/Include/Library/JsonLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,23 @@ JsonObjectSetValue (
IN EDKII_JSON_VALUE Json
);

/**
The function is used to delete a JSON key from the given JSON bject,
@param[in] JsonObj The provided JSON object.
@param[in] Key The key of the JSON value to be deleted.
@retval EFI_ABORTED Some error occur and operation aborted.
@retval EFI_SUCCESS The JSON value has been deleted from this JSON object.
**/
EFI_STATUS
EFIAPI
JsonObjectDelete (
IN EDKII_JSON_OBJECT JsonObj,
IN CONST CHAR8 *Key
);

/**
The function is used to get the number of elements in a JSON array. Returns or 0 if JsonArray
is NULL or not a JSON array.
Expand Down
24 changes: 24 additions & 0 deletions RedfishPkg/Library/JsonLib/JsonLib.c
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,30 @@ JsonObjectSetValue (
}
}

/**
The function is used to delete a JSON key from the given JSON bject
@param[in] JsonObj The provided JSON object.
@param[in] Key The key of the JSON value to be deleted.
@retval EFI_ABORTED Some error occur and operation aborted.
@retval EFI_SUCCESS The JSON value has been deleted from this JSON object.
**/
EFI_STATUS
EFIAPI
JsonObjectDelete (
IN EDKII_JSON_OBJECT JsonObj,
IN CONST CHAR8 *Key
)
{
if (json_object_del ((json_t *)JsonObj, (const char *)Key) != 0) {
return EFI_ABORTED;
} else {
return EFI_SUCCESS;
}
}

/**
The function is used to get the number of elements in a JSON array. Returns or 0 if JsonArray
is NULL or not a JSON array.
Expand Down

0 comments on commit 9971b99

Please sign in to comment.