UPDATED (TESTED) ANSWER:
You can receive the API response as a string, using the "Store as a string" option here, then use the Java action below to to find any instances of [ ":", "^", "|" ] inside the JSON and replace them, perhaps with a hyphen ("-"). Then, you could parse that string using the Import with Mapping activity. In your JSON structure, you'll need to of course manually replace those illegal characters with the hyphen.
Full Solution:
The trick to this is writing the correct regular expression to find the offending characters. Here's the regex I came up with:
("[^"]+?)([:|^])([^"]+?"\s*:)
Then, the replacement string should be:
$1-$3
which will keep groups 1 and 3 from your regex (the stuff in a JSON key except the illegal character), and put a hyphen between them.
Use these in a call to this 1-line Java action (download link for 7.16 here, download this file and right-click on your module and select "Import document from file"):
return originalString.replaceAll(regex, replacement);
Note: you cannot use the built-in replaceAll function in Mendix because the "replacement string" parameter does not support groups/tokens.
With this setup, the original string:
"metatags": [
{
"viewport": "width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no",
"og|title": "John Hennessy and David Patterson Deliver Turing Lecture at ISCA 2018",
"og^description": "webpage to host livestream of hennessy-patterson turing lecture",
"og:type": "website",
"og:image": "https://www.acm.org/images/acm_rgb_grad_pos_diamond.png",
"twitter:card": "summary_large_image",
"twitter:site": "@theofficialacm",
"twitter:title": "John Hennessy and David Patterson Deliver Turing Lecture at ISCA 2018",
"twitter:description": "webpage to host livestream of hennessy-patterson turing lecture",
"twitter:image": "https://www.acm.org/images/acm_rgb_grad_pos_diamond.png",
"og:url": "https://www.acm.org/hennessy-patterson-turing-lecture"
}
],
becomes this:
"metatags": [
{
"viewport": "width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no",
"og-title": "John Hennessy and David Patterson Deliver Turing Lecture at ISCA 2018",
"og-description": "webpage to host livestream of hennessy-patterson turing lecture",
"og-type": "website",
"og-image": "https://www.acm.org/images/acm_rgb_grad_pos_diamond.png",
"twitter-card": "summary_large_image",
"twitter-site": "@theofficialacm",
"twitter-title": "John Hennessy and David Patterson Deliver Turing Lecture at ISCA 2018",
"twitter-description": "webpage to host livestream of hennessy-patterson turing lecture",
"twitter-image": "https://www.acm.org/images/acm_rgb_grad_pos_diamond.png",
"og-url": "https://www.acm.org/hennessy-patterson-turing-lecture"
}
],
Once you have the updated string, you can pass it to the mapping activity.
Let us know if you have any issues!
I know, you changed from $1-$2 to $1-$3 and i saw some little changes.
Thank you.
But the importing problem remains since the properties that had been changed (from : to - )before the JSON Structure, are no more recognised in the http Response.
Unfortunately i still need them.
So i need a way to parse the JSON Structure with [:,^,|] okay actually, [^,|] are not necessary.
I will continue working on it tomorrow
Thanks a lot for the help until this point
Soh
It finally worked, and i thank you guys for your support.
Best
Soh