Save JSON output to variable

Hello All,

I need help with saving a JSON output coming from GPT ‘result’ to ‘set variable’ module.

This is my input for the ‘set variable’ module, exactly as it comes from the GPT ‘result’

```json
{
  "name_1": "John",
  "name_2": "John Doe",
  "description": "This is a description.",
  "question": "This is a question.",
  "answer": "This is an answer.",
  "job_instructions": {
    "job_schedule": "This is a schedule.",
    "job_requirements": "This is a requirement.",
    "job_type": "This is a job type.",
    "Position": "This is a position.",
    "another_variable": "Variable data."
  },
  "job_status": "Job status.",
  "additional_notes": "Additional notes."
}

I would like to save it as variables,

EX.

Name 1
John

Name 2
John Doe

Description
This is a description.....

And so on.

I tried using:

{{result__name_1}}


But it saves the entire 'result' value in the variable.

Please advise.

You need to use a Parse JSON module.

Module Export

You can copy and paste this module export into your scenario. This will paste the modules shown in my screenshots above.

  1. Copy the JSON code below by clicking the copy button when you mouseover the top-right of the code block
    Screenshot_2024-01-17_200117

  2. Enter your scenario editor. Press ESC to close any dialogs. Press CTRLV (paste keyboard shortcut for Windows) to paste directly in the canvas.

  3. Click on each imported module and save it for validation. You may be prompted to remap some variables and connections.

Click to Expand Module Export Code

JSON - Copy and Paste this directly in the scenario editor

{
    "subflows": [
        {
            "flow": [
                {
                    "id": 3,
                    "module": "json:ParseJSON",
                    "version": 1,
                    "parameters": {
                        "type": ""
                    },
                    "mapper": {
                        "json": "{{replace(2.result; \"/(^```.+\\s*|\\s*```$)/g\"; emptystring)}}"
                    },
                    "metadata": {
                        "designer": {
                            "x": 242,
                            "y": -2,
                            "messages": [
                                {
                                    "category": "last",
                                    "severity": "warning",
                                    "message": "A transformer should not be the last module in the route."
                                }
                            ]
                        },
                        "restore": {
                            "parameters": {
                                "type": {
                                    "label": "Choose a data structure"
                                }
                            }
                        },
                        "parameters": [
                            {
                                "name": "type",
                                "type": "udt",
                                "label": "Data structure"
                            }
                        ],
                        "expect": [
                            {
                                "name": "json",
                                "type": "text",
                                "label": "JSON string",
                                "required": true
                            }
                        ]
                    }
                }
            ]
        }
    ],
    "metadata": {
        "version": 1
    }
}

samliewrequest private consultation

Join the Make Fans Discord server to chat with other makers!

2 Likes

HI @arproy

Please ensure that your prompt has user, assistant and system to strictly output JSON data.

Then, you can easily parse the JSON with Parse JSON module.

Regards,
Msquare Automation - Gold Partner of Make

Book a Free Consultation | Connect Live

Explore our YouTube Channel for valuable insights and updates!

1 Like

@samliew Thank you! It works :slight_smile:

I get the required data using the JSON parse module. Some date, however is in the array format. Ex.

"job_instructions": {
    "job_schedule": "This is a schedule.",
    "job_requirements": "This is a requirement.",
    "job_type": "This is a job type.",
    "Position": "This is a position.",
    "another_variable": "Variable data."
  },

I need to save all of this data to a single variable something like this:

1.This is a schedule.
2.This is a requirement.
3.This is a job type.
4.This is a position.
5.Variable data.

What’s the best way to achieve this?

I tried the text aggregator, but the problem is, if I have multiple arrays, I need to add multiple text aggregator modules. A simple solution would be appreciated.

Thanks

I don’t see any arrays, did you mix up arrays and collections?

If you want individual variables you can use the Set Multiple Variables module.

Anyway this is now a different problem. Could you please create a separate topic for this?

While it’s tempting to continue an existing thread, a more effective approach would be to start a new topic. It helps other community users to respond to your query, and keeps our space organised for everyone. If you start a new conversation you are also more likely to get help from other users. You can refer others back to a related topic by including that link in your question. Thank you for understanding and keeping our community neat and tidy.

The “New Topic” link can be found in the top-right of the header:

Thank you!

Join the Make Fans Discord server to chat with other makers!

1 Like