argumentsAsJsonOrNull

fun FunctionCallItem.argumentsAsJsonOrNull(json: Json = Json): JsonObject?

Parses FunctionCallItem.arguments into a JsonObject, or returns null when the model produced malformed JSON or a JSON value that is not an object.

Example:

val call = response.functionCalls.firstOrNull()
val city = call?.argumentsAsJsonOrNull()?.get("city")?.jsonPrimitive?.content

Return

The parsed arguments, or null if they are not a valid JSON object.

Parameters

json

Json instance used for parsing; the default is sufficient for plain argument objects.