Need to join the input array of objects to string

Hi
The json input I get to the pipeline is array of objects. I need iterate each object data and join as a string.
Also I need to append some html code in between.
Ex: input json
“chathist”: [{
“created_by”: “test”,
“created_date”: 1626244986151,
“information_type”: “Request”,
“text”: "Account ",
“content”: “”,
“content_type”: “Question”
}, {
“created_by”: “WsswW”,
“created_date”: 1626244990226,
“information_type”: “Response”,
“text”: "Clicca sulla Società alla quale ",
“content”: “”,
“content_type”: “text”
}, {
“created_by”: “test”,
“created_date”: 1626244998853,
“information_type”: “Request”,
“text”: “example test456”,
“content”: “”,
“content_type”: “srn”
}
]

This input array of objects need to parse and join as string. First I need to check array length > 0
I have similar logic using JSonata. I am trying to achieve this using Expression builder.

{{ $count($Request.Hist ) > 0 ?
$join( [ “[code]

[code]

" & $Header & “


”,
$join($Request.ChatHist.($.content_type != “srn” ? ($.created_by=“abc” ? “[code]” & “VA: " &”” : "[code]

Can we use JSonata in Snaplogic… ? if not how we can achieve this through expression builder. I tried few ways using Array and String function but did not resolve.
Pls suggest.
thanks
arun

Hi @arunnp,

Check if this is the correct format according to your requirement:

If it is, use the following expression in a mapper:

$chathist.length > 0 ? $chathist.map(x=>x.toString().replaceAll(’,’,’&’).replace(/{|}/gi,’’)) : $chathist

Hi @bojanvelevski Thanks for reply.
I am not looking for concatenating the fields as string. The requirement is go through each object in the array appending the “text” field value inside the “content” object.
Below is the sample jsonata expression for this

the sample array is like this
“chathist”: [{
“created_by”: “Test”,
“text”: “Account”,
“content”: “”,
“content_type”: “Question”
}, {
“created_by”: “Test”,
“text”: “Clicca sulla ttger alla wrtr rtwt l’rewrre er deve ererg la :

  • <a role=“button” tabindex=“0” class=“mccs-input”>ffdgc!”,
    “content”: “”,
    “content_type”: “text”
    }, {
    “created_by”: “Test”,
    “text”: "Management ",
    “content”: “”,
    “content_type”: “Question”
    }, {
    “created_by”: “Test”,
    “text”: "Quale resettare?

    • <a role=“button” ",
      “content”: “”,
      “content_type”: “text”
      }, {
      “created_by”: “Test”,
      “text”: “Reset Xchanging”,
      “content”: “”,
      “content_type”: “Question”
      }, {
      “created_by”: “Test”,
      “content_type”: “Mps”,
      “content”: {
      “intent”: “changing”,
      “video_URL”: null,
      “solution_URL”: “”,
      “title”: “Reset changing”,
      “text”: "Scriva una e-mail a xch-helpdesk@xchanging.it<span style=“color: black;”>oppure si sul desktop l’icona "
      }
      }]
      thanks
      arun

The samples you are sending are pretty hard to understand. Send one sample object before the transformation, and one after, and use the Preformatted text option while posting JSON data.

the sample input.

"chathist": [{
		"created_by": "Test",
		"text": "Account",
		"content": "",
		"content_type": "Question"
	}, {
		"created_by": "USer1",
		"text": "Clicca sulla ttger alla wrtr rtwt l'rewrre er deve ererg la :<b><br><br><ul><li><a role=\"button\" tabindex=\"0\" class=\"mccs-input\">ffdgc!</a>",
		"content": "",
		"content_type": "text"
	}, {
		"created_by": "User1",
		"text": "Management ",
		"content": "",
		"content_type": "Question"
	}, {
		"created_by": "Test",
		"text": "Quale resettare?<b><br><br><ul><li><a role=\"button\" ",
		"content": "",
		"content_type": "text"
	}, {
		"created_by": "User1",
		"text": "Reset  Xchanging",
		"content": "",
		"content_type": "Question"
	}, {
		"created_by": "User1",
		"content_type": "Mps",
		"content": {
			"intent": "changing",
			"video_URL": null,
			"solution_URL": "",
			"title": "Reset changing",
			"text": "Scriva una e-mail a<strong> xch-helpdesk@xchanging.it</strong><span style=\"color: black;\">oppure si  sul desktop l'icona </span>"
		}
	}]

the example sample output.

VA history:
User1: IBM Demo: What is LUCA
VA: What is MNCQ Answer: MNCQ stands for dafsasf. 
User1: Marked the solution NOT helpful. Comment: needs additional detail
VA: Feedback recorded
VA: feedback to improve. view the other.
User1: window login
VA: Please click for your query. If you do not wish ask any other question.

@bojanvelevski , I tried few ways using expression builder I did not get the formatted msg.
Any suggestions will be helpful.
thanks
arun

Any suggestions or help…?
for the requirement I mentioned above…

thanks
arun

Hi @arunnp,

You want to make a string of all objects in the array ? Can you share a little bit more info on how did you get that sample output from that sample input data ? I don’t think I understand that. For example, what output do you want this object to give you ?

{
		"created_by": "USer1",
		"text": "Clicca sulla ttger alla wrtr rtwt l'rewrre er deve ererg la :<b><br><br><ul><li><a role=\"button\" tabindex=\"0\" class=\"mccs-input\">ffdgc!</a>",
		"content": "",
		"content_type": "text"
}

Something like this ?

User1: Clicca sulla ttger alla wrtr rtwt l'rewrre er deve ererg la :<b><br><br><ul><li><a role=\"button\" tabindex=\"0\" class=\"mccs-input\">ffdgc!</a></li></ul></b>

Hi @j.angelevski

Yes, want to prepare a formatted string by reading the particular field from all objects. The Jsonata expression we are currently using I pasted above.
The sample input

{
	"chatHist": [{
			"created_by": "Info Person",
			"created_date": 1628581678201,
			"information_type": "Request",
			"text": "demo: I'm unable to create a new sale order",
			"content": "",
			"content_type": "Question"
		},
		{
			"created_by": "Test",
			"created_date": 1628581681109,
			"information_type": "Response",
			"text": "",
			"content": [{
				"abstract": "",
				"link": "https://.service-now.com//kb_view.do?sys_kb_id=2ec8ccb5900b44dc8783d452773994d3",
				"title": "Determine why Some People are Unable to Find or View a Web Page Saved on a File Server"
			}],
			"content_type": "srn"
		},
		{
			"created_by": "Test",
			"created_date": 1628581681967,
			"information_type": "Response",
			"text": "Please <a role=\"button\" tabindex=\"0\" class=\"create-ticket\"> click confirm <\/a> to create an incident for your query. If you do not wish to create an incident just ask any other question.",
			"content": "",
			"content_type": "text"
		}
	]
}

After formatting this the string will be

Virtual assistant chat history:

Info Person:demo: I'm unable to create a new sale order
VA: Please click confirm to create an incident for your query. If you do not wish to create an incident just ask any other question.

here we are adding ‘Virtual assistant chat history:’ as heading of the string.

VA.-> replacement for the “created_by”: “Test”. field value.
I hope I gave details.

thanks
arun

I created two solutions for this:

  1. Output a string

  2. Output html string

You can download the pipeline here
ChatHistory_Community_2021_08_10.slp (12.6 KB)

The problem here is what happens with those objects that don’t have the text field ? What happens when content-type is something else than text ? For now the pipeline I attached is not omitting those fields with empty text or where content-type is not text, it will simply display it as empty string.

Sample output from pipeline solution 1:

Virtual assistant chat history:

Info Person: demo: I'm unable to create a new sale order
Test: 
Test: Please <a role="button" tabindex="0" class="create-ticket"> click confirm </a> to create an incident for your query. If you do not wish to create an incident just ask any other question.

Sample html output from solution 2:

<body><h1>Virtual assistant chat history:</h1><br/><p>Info Person : demo: I'm unable to create a new sale order</p><p>Test : </p><p>Test : Please <a class="create-ticket" role="button" tabindex="0"> click confirm </a> to create an incident for your query. If you do not wish to create an incident just ask any other question.</p></body>

Of course the html output is not formatted here but you can see how it looks on jsfiddle:

@j.angelevski Thanks fo the solution.
I used your approach to implement the logic to loop through complete input array to read data and to create a formatted text message.
regds
arun