NHS API response has unusual syntax {\"KEY\":\"VALUE\"}

I’m trying to consume an NHS API, but LibertyCreate is not letting me map the response with an API call response template because the syntax is invalid.

“Contacts”:[​{\“OrganisationContactType\”:\“organisation contact type\”,\“OrganisationContactAvailabilityType\”:\“organisation contact availability type\”,\“OrganisationContactMethodType\”:\“organisation contact method type\”,\“OrganisationContactValue\”:\“organisation contact value\”}​]`

Can anyone offer any advice? The problem seems to be the existence of the \. I think I could save the entire value of the array to a text multi line and the write some code to parse it, but i’d prefer not to.

Wait a minute! This is where I should use the “Response payload preprocessor” isn’t it.

Hi Craig,
I believe you guessed it right: it is time to write a Response Payload Preprocessor.
A preprocessor that gets rid of the backslashes () in this string. Once done the rest of the response payload seems a valid JSON string i.e. " “:” "

Hi Craig, that is actually JSON converted to a string - I would be tempted not to just get rid of the backslashes as you may miss some other things. Useful starting point for a data processor:

var transformed_fields = params.fields;
var payload = JSON.parse (transformed_fields.payload);
// mats.log (JSON.stringify(payload));

Hi @richk, brilliant. Thank you!

1 Like