Help to create nested JSON

Hello,

I’m trying to send data to Mistral IA API.
I’m building a call with random numbers of documents as input (Mistral will generate an email with explanations to my students).

I need to create a “messages” structure like that:

{
    "role": "user",
    "content": [
        {
            "type": "text",
            "text": "User query about documents"
        },
        {
            "type": "document_url",
            "document_url": "https://pdf.com/doc1"
        },
        {
            "type": "document_url",
            "document_url": "https://pdf.com/doc2"
        },
        {
            "type": "document_url",
            "document_url": "https://pdf.com/doc3"
        }
    ]
}

I have used different aggregator, but I never got close to what I need:

My idea is to create a JSON with the user prompt and then to add the document list. But I have the feeling is not the way I should think using Make.

Could somebody give me a hint please?
Many thanks for your help :slight_smile: !

Hey there,

can you share what the input you are starting from is?

Either Create JSON, Transform to JSON or Aggregate to JSON should do the trick, but it depends on what the incoming data is.

Hello Stoyan,

At the moment I start manually (I will trigger automatically later).
Then I list files on OneDrive:

Then I need:
To create a JSON with
{
“role”: “user”,
“content”:
}

The fist part of “content” is set “manually”:

        {
            "type": "text",
            "text": "My user prompt"
        },

And I want to append the links to the files:

        {
            "type": "document_url",
            "document_url": "https://pdf.com/doc1"
        },
        {
            "type": "document_url",
            "document_url": "https://pdf.com/doc2"
        },
        {
            "type": "document_url",
            "document_url": "https://pdf.com/doc3"
        }

I tried with a JSON aggregator:

That is not what I need for the links to files:

[
{
“doc”: {
“type”: “document_url”,
“document_url”: “https://1drv.ms/b/doc1
}
},
{
“doc”: {
“type”: “document_url”,
“document_url”: “https://1drv.ms/b/doc2
}
}
]

With a text aggregator + :


I can get the right JSON as string:

Parsing is successful:

Then I don’t understand how to integrated the string I created using JSON blocks. My string is “escaped”:

At this point:

  • I’m stuck with JSON utilities in Make
  • I fail to create JSON string manually that are valid in a “Create JSON module”

I hope I’m clear enough :slight_smile: !