summaryrefslogtreecommitdiffstats
path: root/RedfishPkg
diff options
context:
space:
mode:
Diffstat (limited to 'RedfishPkg')
-rw-r--r--RedfishPkg/Include/Library/JsonLib.h21
-rw-r--r--RedfishPkg/Library/JsonLib/JsonLib.c26
2 files changed, 47 insertions, 0 deletions
diff --git a/RedfishPkg/Include/Library/JsonLib.h b/RedfishPkg/Include/Library/JsonLib.h
index 3c10f67d27..8a30c5250b 100644
--- a/RedfishPkg/Include/Library/JsonLib.h
+++ b/RedfishPkg/Include/Library/JsonLib.h
@@ -665,6 +665,27 @@ JsonDumpString (
);
/**
+ Convert a string to JSON object.
+ The function is used to convert a NULL terminated CHAR8 string to a JSON
+ value. Only object and array represented strings can be converted successfully,
+ since they are the only valid root values of a JSON text for UEFI usage.
+
+ Real number and number with exponent part are not supportted by UEFI.
+
+ Caller needs to cleanup the root value by calling JsonValueFree().
+
+ @param[in] String The NULL terminated CHAR8 string to convert.
+
+ @retval Array JSON value or object JSON value, or NULL when any error occurs.
+
+**/
+EDKII_JSON_VALUE
+EFIAPI
+JsonLoadString (
+ IN CONST CHAR8* String
+ );
+
+/**
Load JSON from a buffer.
@param[in] Buffer Bufffer to the JSON payload
diff --git a/RedfishPkg/Library/JsonLib/JsonLib.c b/RedfishPkg/Library/JsonLib/JsonLib.c
index 34ff381aee..3693299afb 100644
--- a/RedfishPkg/Library/JsonLib/JsonLib.c
+++ b/RedfishPkg/Library/JsonLib/JsonLib.c
@@ -820,6 +820,32 @@ JsonDumpString (
}
/**
+ Convert a string to JSON object.
+ The function is used to convert a NULL terminated CHAR8 string to a JSON
+ value. Only object and array represented strings can be converted successfully,
+ since they are the only valid root values of a JSON text for UEFI usage.
+
+ Real number and number with exponent part are not supportted by UEFI.
+
+ Caller needs to cleanup the root value by calling JsonValueFree().
+
+ @param[in] String The NULL terminated CHAR8 string to convert.
+
+ @retval Array JSON value or object JSON value, or NULL when any error occurs.
+
+**/
+EDKII_JSON_VALUE
+EFIAPI
+JsonLoadString (
+ IN CONST CHAR8* String
+ )
+{
+ json_error_t JsonError;
+
+ return (EDKII_JSON_VALUE) json_loads ((const char *)String, 0, &JsonError);
+}
+
+/**
Load JSON from a buffer.
@param[in] Buffer Bufffer to the JSON payload