You can convert from the text response to a json response using a Map policy. Just invoke the service that returns the application/text reponse and then use a Map policy like this one:
- map:
version: 2.0.0
title: map
inputs:
message.body:
schema:
type: string
variable: message.body
content: text/plain
outputs:
message.body:
schema:
type: object
properties:
response:
type: string
name: response
variable: message.body
content: application/json
actions:
- set: message\.body.response
from: message\.body
Produces a response of:
{"response":"this is a text response string."}
------------------------------
Steve Ruscik
------------------------------
Original Message:
Sent: Sat April 29, 2023 06:46 AM
From: Jyoti Yadav
Subject: Need to Convert String to application/json
Hello Team,
We have received response from Endpoint URL in String format, but the content-type of Response is "application/json", we need to fetch that value and convert it into proper JSON format (ie in Parameter name, value) format.
We have tried to change Content-type of response and convert it, but its shows blank json response (ie {}).
Please help how to convert it into API Connect (V10, V5).
Please find below example for same.
Received Response:
abcdefg
Require response:
{"response":"abcdefg)
Thanks and Regards,
Jyoti
------------------------------
Jyoti Yadav
------------------------------