summaryrefslogtreecommitdiffstats
path: root/RedfishPkg
diff options
context:
space:
mode:
authorAbner Chang <abner.chang@hpe.com>2021-01-29 11:46:53 +0800
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2021-02-24 08:27:09 +0000
commit5d7b5cd10569f3098c8a51c10a94bf2f6cc45bf5 (patch)
tree2f92fc98ddbd83258c6f830bb703499e44d22645 /RedfishPkg
parent739a506b18c4f694b8d5d2f3424a329c45d737ba (diff)
downloadedk2-5d7b5cd10569f3098c8a51c10a94bf2f6cc45bf5.tar.gz
edk2-5d7b5cd10569f3098c8a51c10a94bf2f6cc45bf5.tar.bz2
edk2-5d7b5cd10569f3098c8a51c10a94bf2f6cc45bf5.zip
RedfishPkg/JsonLib: Add JsonLoadString function
Add JsonLoadString function to load a NULL terminated-string JSON Signed-off-by: Abner Chang <abner.chang@hpe.com> Cc: Leif Lindholm <leif@nuviainc.com> Cc: Nickle Wang <nickle.wang@hpe.com> Cc: Michael D Kinney <michael.d.kinney@intel.com> Reviewed-by: Nickle Wang <nickle.wang@hpe.com>
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