1

I have a Json Input string , while parsing the Json the Description field value is breaking into another line, why this line is breaking

%%[
    var @Json
    set @Json = '{
        "ArticleCount": 22,
        "Description": "<Content><fig id=\"ehx401-F1\" orientation=\"portrait\" position=\"float\"><label>Figure 1</label><caption><p>Causes of hospital readmission by timing of occurrence. Distribution of causes of hospital readmission according to the timing of their occurrence since discharge after the procedure. (From Franzone A, Pilgrim T, Arnold N, Heg D, Langhammer B, Piccolo R, Roost E, Praz F, Räber L, Valgimigli M, Wenaweser P, Jüni P, Carrel T, Windecker S, Stortecky S. Rates and predictors of hospital readmission after transcatheter aortic valve implantation. See pages: 2211–2217).</p></caption><graphic orientation=\"portrait\" position=\"float\" href=\"ehx401f1.tif\" /></fig></Content>"
    }'
]%%

{{.datasource JSONVar type=variable maxrows=20}}
    {{.data}}
        {"target" :"@json" }
    {{/data}}
    ArticleCount:{{ArticleCount}}<br/>
    Description:{{Description}}<br/>
{{/datasource}}

Output is displaying like:

Causes of hospital readmission by timing of occurrence. Distribution of causes of hospital readmission according to the timing of their occurrence since discharge after the procedure. (From Franzone A, Pilgrim T, Arnold N, Heg D, Langhammer B, Piccolo R, Roost E, Praz F, Räber L, Valgimigli M, Wenaweser P, Jüni P, Carrel T, Windecker S, Stortecky S. Rates and predictors of hospital readmission after transcatheter aortic valve implantation. See pages: 2211–2217).

ArticleCount:22
Description:Figure 1

Actually the Description Value should have to come after Figure1, but it is displaying at the top,How to Rectify this mistake?

  • Try reversing the order in your code? – Samuel Dare Aug 17 '17 at 11:01
  • I meant declaring article count before decision value. Might yield the intended results – Samuel Dare Aug 17 '17 at 11:07
  • Why do you have two usernames? – Samuel Dare Aug 17 '17 at 11:16
  • 'If i am not declaring the article count, i am displaying description field value only, but again same output is coming @Data_Kid – user47136 Aug 17 '17 at 11:20
2

When I use your code, I see that the order appears correctly.

I suspect the issue that you are experiencing is related to your XML, as you are using unsupported HTML elements:

  • Content
  • fig
  • graphic
  • caption

*caption is a supported HTML element, but only in tables and must be inserted immediately after the <table> tag.

Also their respective attributes such as orientation and position are unknown to the User Agent and is causing unexpected results when you display them.

I would recommend:

  1. Removing the unsupported orientation and position attributes
  2. Change content, fig and caption* to a supported element, like div
  3. Change graphic to img

You may also want to consider writing an XSL template to transform the XML to supported HTML and use this in conjunction with the AMPscript TransformXML function.

|improve this answer|||||
  • ,How to use TransformXML function for description value in this scenario can you guide me the code @Eliot Harper – SFDC Aug 18 '17 at 5:14
  • Hello, please understand SFSE is not a code writing service. If you are unfamiliar with XSL, there are many resources available online. – Eliot Harper Aug 18 '17 at 5:52
  • ok sorry, thank you for giving valid answer for this question@Eliot Harper – SFDC Aug 18 '17 at 6:10
  • I have another doubt,set Json = '{ "ArticleCount": 22, "Description": "<Content><fig id=\"ehx401-F1\" orientation=\"portrait\" position=\"float\"><label>Figure 1</label>"},{ "ArticleCount": 22, "Description": "<Content><fig id=\"ehx401-F1\" orientation=\"portrait\" position=\"float\"><label>Figure 1</label>" }',if json input values is repeatedly coming same value, i want to iterate the same process, how @Eliot Harper,can you guide me for this scenario – SFDC Aug 18 '17 at 6:22
  • I assume you would like to loop through and display objects in an array. I've created an example which does this (just copy the code and preview any Subscriber and you will see it working). Download the example html here. – Eliot Harper Aug 18 '17 at 6:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy