Convert Gemini API data to plain text

Ways to convert data form Gemini or ChatGPT to plain text without using API’s

So i have a json response in the text. Which is fine, but how can i convert this to plain text? Because i want to sent it to the ga4 data api and it doesn’t likes the json format this way. If you transfer it in text or use it in states the json format is still there. What can i do to transform this to plain text? Without plugins or external services please.


You can use raw body text as to get plain text of the response and then send it you can send it to another API via: <your json object:format as text (JSON-safe)>

Hey @tarasmuzon thanks for the reply. Raw body text remains empty. That’s the whole problem… i only need the raw text without the /n characters but in a normal text body. The /n characters don’t appear.

Ah. Check “capture response headers”. That’s when raw body becomes available.

@tarasmuzon also have that one checked. It is only the raw body text of the content part that it is empty.

Hi Tom,

I recorded a video about this topic. Please let me know if it solves your problem.

So you only need “parts” of your response as raw text, not full response?

If so, do what @douglas.epr, although API calls will be WU expensive if you are doing a lot.

If you don’t want to do API Connector you can use Toolbox plugin (I know you said no plugins, but API Connector and Toolbox are kinda my default ones for any project):

return JSON.parse(properties.input.body.candidates[0].content.parts[0]);

If you really don’t want to use Toolbox and API Connector - the last resort is probably regex :sweat_smile:

2 Likes

I get a 400 missing data message. “Missing parameter for workflow convert_json: parameter input”}}

Json that i used: “{"properties": [{"property": "properties/YOUR_GA4_PROPERTY_ID"}], "dateRanges": [{"startDate": "2024-06-01", "endDate": "2024-06-30"}], "dimensions": [{"name": "date"}, {"name": "sourceMedium"}], "metrics": [{"name": "activeUsers"}, {"name": "sessions"}, {"name": "totalUsers"}], "orderBys": [{"dimension": {"dimensionName": "date"}}, {"metric": {"metricName": "activeUsers"}, "desc": true}], "limit": 1000, "keepEmptyRows": false}”




Hi Tom,
JSON text should be sent in stringfied format, like the one below. Just add in the expression end the operator “:formatted as JSON safe”

“{"properties":[{"property":"properties/YOUR_GA4_PROPERTY_ID"}],"dateRanges":[{"startDate":"2024-06-01","endDate":"2024-06-30"}],"dimensions":[{"name":"date"},{"name":"sourceMedium"}],"metrics":[{"name":"activeUsers"},{"name":"sessions"},{"name":"totalUsers"}],"orderBys":[{"dimension":{"dimensionName":"date"}},{"metric":{"metricName":"activeUsers"},"desc":true}],"limit":1000,"keepEmptyRows":false}”

Hey, douglas. It was the content type. I did not put application/json to it. but only application. Works now, thanks! It would help in the video if you would have a use case showing the result and an example. But the rest was great to follow.

1 Like

I was to fast, this only makes the data usable but I want this content exactly in the api. If i get it into a bubble data format. i still have the same problem, because i don’t have the report in raw data…

I only split the report into different data types using this action. I cannot get the data raw into this one field. Which is the only thing i need. Because the report is already good. I only need to transfer the json to raw text format withou jsonsafe.

the result i need is this:

{
“dateRanges”: [
{
“startDate”: “31daysAgo”,
“endDate”: “yesterday”,
“name”: “Selected_period”
}
],
“dimensions”: [
{
“name”: “firstUserDefaultChannelGroup”
},
{
“name”: “firstUserSourceMedium”
}
],
“metrics”: [
{
“name”: “eventCount”
},
{
“name”: “bounceRate”
},
{
“name”: “averageSessionDuration”
}
]
}

Which changes based on the AI outplut.

Got it.
You can use Result of step 2’s body properties:format as text and create this JSON manually.

Then i’m not getting any data…



The correct is something like “This body …name” instead “Result of step 2…” as you inserted on “name”.

Hey Douglas, thanks for the reply! So the problem with this is that I cannot format it earlier. Have to make a choice.

So when you choose result 2 and then date ranges. You still need to add the name and metrics dimensions

and they can all change.

So sometimes I will need 2 dateranges, 1 dimension and 5 metrics and 1 filter

and then 1 daterange, 2 dimensions and 1 metric and 0 filters.

So I need to have it within the same row no?

I think I understood. Dates data type is not coming in the correct format.
Try to receive dates as a text and inserting conditionals, like: “This text is 'yesterday:Format as text: (current date/time + days: -1”

Hey Douglas, that is not what i ment. I mean that the format of the script can change. The daterange is fine the way it is. Don’t focus on that