2014 Nov 18 3:45 PM
hi Experts
I apologize if there are examples of this already and I am simply searching incorrectly. I have however looked and cannot find an example solution or guidance to transform a JSON response like the one below, into an internal table.
The response I get is like this:
{"userAgreementList":[{"displayDate":"2014-11-17T09:58:13-08:00","displayUserInfo":{"fullNameOrEmail":"[email protected]"},"esign":true,"agreementId":"xxxx","latestVersionId":"xxx","name":"test","status":
"OUT_FOR_SIGNATURE"},{"displayDate":"2014-11-17T08
:27:04-08:00","displayUserInfo":{"company":"xx","fullNameOrEmail":"x"},"esign":true,"agreementId":"xxx","latestVersionId":"xx","name":"test":"SIGNED"}]}
As you can see I have the sub section fullNameOrEmail which I cant seem to get correctly into an internal table. I keep getting the match exception upon transformation.
Anyhow, I appreciate any help given.
Thank you kindly!
Chris
2014 Nov 18 10:36 PM
Hi Chris,
Could you share some code so we can see what might be wrong?
Cheers,
Custodio
Hi Chris,
Could you share some code so we can see what might be wrong?
Cheers,
Custodio
2014 Nov 18 10:36 PM
Hi Chris,
Could you share some code so we can see what might be wrong?
Cheers,
Custodio
2014 Nov 19 2:12 AM
hi Custodio,
I make a call to get the JSON response, so
CALL METHOD send_get_request
EXPORTING
iv_url = rest_url
it_header_params = lt_params
RECEIVING
rv_response = l_json.
l_json looks like this:
{
"userAgreementList":
[{"displayDate":"2014-11-17T09:58:13-08:00",
"displayUserInfo":{"fullNameOrEmail":"[email protected]"},
"esign":true,"agreementId":"xxxx","latestVersionId":"xxx","name":"test","status":
"OUT_FOR_SIGNATURE"},
{"displayDate":"2014-11-17T08
:27:04-08:00",
"displayUserInfo":{"company":"xx","fullNameOrEmail":"x"},"esign":true,"agreementId":"xxx","latestVersionId":"xx","name":"test":"SIGNED"}]}
then I call ID transformation to process.
CALL TRANSFORMATION id SOURCE XML l_json RESULT useragreementlist = rt_agreements
I continue to get the CX_ST_MATCH exception.
If I do:
REPLACE FIRST OCCURRENCE OF 'userAgreementList' IN l_json WITH 'USERAGREEMENTLIST'.
REPLACE ALL OCCURRENCES OF 'displayDate' IN l_json WITH 'DISPLAY_DATE'.
REPLACE ALL OCCURRENCES OF 'fullNameOrEmail' IN l_json WITH 'FULL_NAME_OR_EMAIL'.
REPLACE ALL OCCURRENCES OF 'esign' IN l_json WITH 'ESIGN'.
REPLACE ALL OCCURRENCES OF 'agreementId' IN l_json WITH 'AGREEMENT_ID'.
REPLACE ALL OCCURRENCES OF 'name' IN l_json WITH 'NAME'.
REPLACE ALL OCCURRENCES OF 'status' IN l_json WITH 'STATUS'.
CALL TRANSFORMATION id SOURCE XML l_json RESULT useragreementlist = rt_agreements.
I get display_date, esign, agreement_id, name, status.
I am missing company, fullnameoremail and latestversionid,
hope that helps. I appreciate anything you can do!
Thx
Chris
2014 Nov 19 2:24 AM
So, I just tried something. I created a structure and table type for the displayuserinfo object and added it to my agreements structure. I did the following and now I get the data.
REPLACE FIRST OCCURRENCE OF 'userAgreementList' IN l_json WITH 'USERAGREEMENTLIST'.
REPLACE ALL OCCURRENCES OF 'displayDate' IN l_json WITH 'DISPLAY_DATE'.
REPLACE ALL OCCURRENCES OF 'fullNameOrEmail' IN l_json WITH 'FULL_NAME_OR_EMAIL'.
REPLACE ALL OCCURRENCES OF ',"esign' IN l_json WITH '], "ESIGN'.
REPLACE ALL OCCURRENCES OF 'agreementId' IN l_json WITH 'AGREEMENT_ID'.
REPLACE ALL OCCURRENCES OF 'name' IN l_json WITH 'NAME'.
REPLACE ALL OCCURRENCES OF 'status' IN l_json WITH 'STATUS'.
REPLACE ALL OCCURRENCES OF 'displayUserInfo":' IN l_json WITH 'DISPLAY_USER_INFO":['.
Shouldn't there be some other standard way to get this data without having to hack it up like this? The structure/table type isnt the issue but all the replace statements is insane depending on the JSON response.
2014 Nov 19 2:32 AM
Hi Chris,
Believe or not, this solution is pretty much what I was going to suggest
Yes, it should be a better/easier way. Maybe if you use 's ZJSON it helps?
Cheers,
Custodio
| User | Count |
|---|---|
| 6 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |