That is the AI model writing a markdown code block fence, for display in a user interface like ChatGPT does.
You have to make clear in a system message that the AI is automated, has no user to interact with, has no display and no renderer of markdown, output is being sent directly to an API, and using any markdown and starting a response with any other character than “{” is prohibited.
GPT-4 doesn’t have any special JSON mode, it is older than the announcement of the feature with gpt-4-turbo.
Reduce the top_p setting significantly below the default of 1.0, so the AI can produce reliably.