1
How to map JSON ArrayList?
Question asked by Oliver Ruppert - 3/8/2019 at 7:17 AM
Answered
Hello,
 
I have problems with the mapping of JSON ArrayList with dynamic number of Items. That means, first call I have i.e. 2 Items. Next call 5 Items.
 
Here first example of JSON Source:
{
 "email": "first.last@company.com",
 "costs": 12.34,
 "attachments": [
  {
   "id": "d9274e6a-f880-4a07-a356-50e65af711b5",
   "fileName": "text1.txt"
  },
  {
   "id": "142efeff-6cf1-461e-b210-e0601539be23",
   "fileName": "pdf1.pdf"
  },
  {
   "id": "e85e354a-dd66-43e0-9f07-0fa3d9f592f9",
   "fileName": "image1.PNG"
  }
 ]
}
 
Here second example of JSON Source:
{
 "email": "name.lastname@company.com",
 "costs": 43.21,
 "attachments": [
  {
   "id": "142efeff-8888-461e-b210-e0601539be23",
   "fileName": "file1.xls"
  },
  {
   "id": "e85e354a-7777-43e0-9f07-0fa3d9f592f9",
   "fileName": "image2.PNG"
  }
 ]
}
 
Both should be transformed and mapped to the target JSON structure, which here is a sample for
Target 1
{
 "Ticket": {
  "Customer": "first last"
 },
 "Attachment": [
  {
   "Filename": "text1.txt"
  },
  {
   "Filename": "pdf1.pdf"
  },
  {
   "Filename": "image1.PNG"
  }
 ]
}
 
and here a sample for the seond target:
{
 "Ticket": {
  "Customer": "name lastname"
 },
 "Attachment": [
  {
   "Filename": "file1.xls"
  },
  {
   "Filename": "image2.PNG"
  }
 ]
}
I don't know how to manage this with one DataMapper with JSON Input and JSON Output.
A simple mapping from "fileName" -> "Filename" will result in this:
 
/*Created by Liquid Data Mapper Libraries (url) for UNLICENSED TRIAL VERSION FOR EVALUATION USE ONLY*/
{
 "Ticket": {
  "CustomerUser": "first last"
 },
 "Attachment": [
  {
   "Filename": "text1.txt pdf1.pdf image1.PNG"
  }
 ]
}

Can somebody help me and give some advise?
 
Thanks very much
Oliver

1 Reply

Reply to Thread
1
Oliver Ruppert Replied
Marked As Answer
I found the solution.
It's necessary to connect all the nodes to each other:
 
 
The the result would be like expected:
/*Created by Liquid Data Mapper Libraries (url) for UNLICENSED TRIAL VERSION FOR EVALUATION USE ONLY*/
{
 "Ticket": {
  "CustomerUser": "first last",
  "costs": 12.34
 },
 "Attachment": [
  {
   "Filename": "text1.txt"
  },
  {
   "Filename": "pdf1.pdf"
  },
  {
   "Filename": "image1.PNG"
  }
 ]
}
 

Reply to Thread