Bug: Prompting for JSON output and then response appending curly brace after the array

Using either the API or Studio, I ask Google Gemini 1.5 Flash to “return all extracted objects as a valid array of valid JSON objects”. The response is an array of objects with a curly brace appended to the end of the JSON string e.g. “ }”. This string is not parsable and throws errors in my code. What’s worse is that the curly brace is appended sometimes.

const generationConfig = {
temperature: 1,
topP: 0.95,
topK: 40,
maxOutputTokens: 8192,
responseMimeType: “application/json”,
};

Anyone know a fix for this? Gemini Pro doesn’t seem to have this issue with the same prompt.