The string data to parse.
Optional
jsonPath: stringThe file path from which the JSON was loaded.
Optional
throwOnEmpty: booleanIf the data contents are empty.
JsonParseError If the data contents are empty or the data is invalid.
JsonDataFormatError If the data contents are not a JsonMap
.
Parse JSON
string
data, expecting the result to be aJsonMap
.If you are the producer of the JSON being parsed or have a high degree of confidence in the source of the JSON (e.g. static resources in your project or unwavering data services of high integrity) then you may provide a more specific type as the type parameter,
T
. This practice is not recommended unless you are fully confident in the ability of the type provided to accurately reflect the parsed data, given that no runtime checks will be performed by this method to validate the JSON. In particular, despite the fact that the provided type must extendJsonMap
, it is possible to circumvent the compiler's ability to do strict null checking by failing to captureundefined
ornull
property states in the types you apply. It's a best practice to mark all properties of such types as optional, especially when in doubt.