def test_json_in_prompt() -> None:
    """Test that a JSON object in the prompt doesn't cause an error."""
    # test with normal prompt
    prompt = PromptTemplate(
        'This is the prompt {text} but it also has {"json": "in it"}'
    )
    prompt.partial_format(text="hello_world")
    prompt_helper = PromptHelper()

    texts = prompt_helper.repack(prompt, ["hello_world"])
    assert len(texts) == 1

    # test with chat messages
    prompt = ChatPromptTemplate.from_messages(
        [
            ChatMessage(
                role="system",
                content="You are a helpful assistant that knows about {topic}. Here's some JSON: {'foo': 'bar'}",
            ),
            ChatMessage(
                role="user",
                content="What is the capital of the moon? Here's some JSON: {'foo': 'bar'}",
            ),
        ]
    )
    prompt.partial_format(topic="the moon")
    prompt_helper = PromptHelper()

    texts = prompt_helper.repack(prompt, ["hello_world"])
    assert len(texts) == 1

    # test with more complex JSON
    prompt = ChatPromptTemplate.from_messages(
        [
            ChatMessage(
                role="system",
                content=(
                    "You are a helpful assistant that knows about {topic}\n"
                    "Here's some JSON: {'foo': 'bar'}\n"
                    "here's some other stuff: {key: val for val in d.items()}\n"
                ),
            ),
            ChatMessage(
                role="user",
                content="What is the capital of the moon? Here's some JSON: {'foo': 'bar'}",
            ),
        ]
    )
Test that a JSON object in the prompt doesn't cause an error.
llama-index-core/tests/indices/test_prompt_helper.py