A simple Bifrost plugin that handles partial JSON chunks in streaming responses by making them valid JSON objects.
PerRequest
mode, the plugin checks for the context key jsonparser.EnableStreamingJSONParser
with a boolean value:
true
: Enable JSON parsing for this requestfalse
: Disable JSON parsing for this requestparsePartialJSON
function with the following steps:
MaxAge
Input | Output |
---|---|
{"name": "John" | {"name": "John"} |
["apple", "banana" | ["apple", "banana"] |
{"user": {"name": "John" | {"user": {"name": "John"}} |
{"message": "Hello\nWorld" | {"message": "Hello\nWorld"} |
"" (empty string) | {} |
" " (whitespace only) | {} |