Not: Saniye değerleri oransal olarak kıyaslama amaçlıdır.

Jolt Kullanma

Performans: 1 sn (En iyisi)

Sample Input

{
   "uId" : null,
   "data" : [
      {
         "id" : 2,
         "version" : 22,
         "code" : "2121001",
         "currency" : {
            "code" : "TL",
         },
         "detail" : "XXX,
         "group" : {
            "id" : 321,
            "name" : "YYY",
            "otherName" : "YYY"
         },
         "code" : null,
         "type" : {
            "id" : 3,
            "name" : "ZZZ",
            "otherName" : "ZZZ"
         },
         "name" : "YYY / AAA: xxx",
         "prodUnit" : {
            "id" : 5,
            "otherName" : "BBB"
         },
         "category" : "CCC",
         "codeName" : "2121001 YYY",
         "Unit" : "BBB"
      }
   ],
   "total" : 13540
}
CODE

JOLT Transformation Code

[

  {
    "operation": "shift",
    "spec": {
      "data": { 
        "*": {
          "id": "data[#2].mat_id",
          "code": "data[#2].mat_code",
          "currency": {
            "code": "data[#3].mat_currency"
          },
          "detail": "data[#2].detail",
          "group": {
            "id": "data[#3].matGroup_id",
            "name": "data[#3].matGroup_name"
          },
          "code": "data[#2].mat_code",
          "type": {
            "id": "data[#3].matType_id",
            "name": "data[#3].matType_name"
          },
          "prodUnit": {
            "otherName": "data[#3].prodUnit_otherName"
          },
          "ategory": "data[#2].mat_category",
          "codeName": "data[#2].mat_codeName",
          "unit": "data[#2].mat_unit",
          "contactInfo": {
            "email": "data[#3].source"
          }
        }
      }
    }
  },
  {
    "operation": "default",
    "spec": {
      "data[]": {
        "*": {
          "mat_id": null,
          "mat_code": null,
          "mat_currency": null,
          "detail": null,
          "matGroup_id": null,
          "matGroup_name": null,
          "matNsnCode": null,
          "matType_id": null,
          "matType_name": null,
          "prodUnit_otherName": null,
          "mat_category": null,
          "mat_codeName": null,
          "matUnit": null,
          "source": "SEM"
        }
      }
    }
  }
]
CODE

Sample Output:

{
  "data" : [ {
    "mat_id" : 3,
    "mat_code" : "2121001",
    "mat_currency" : "TL",
    "detail" : "XXX,
    "matGroup_id" : 321,
    "matGroup_name" : " YYY",
    "matNsnCode" : null,
    "matType_id" : 2,
    "matType_name" : "ZZZ",
    "prodUnit_otherName" : "BBB",
    "matCategory" : "CCC",
    "mat_codeName" : "YYY / AAA: xx",
    "matUnit" : "BBB",
    "source" : "SEM"
  }
  ]
 }
CODE

Groovy JsonPlurp kullanarak 

Performans: 10sn

import  tr.com.soagen.apinizer.util.*;
import groovy.json.JsonSlurper;

String templateJson = "{"+
"\"mat_id\":\"#mat_id\",	"+
...
"}";
 


def jsonSlurper = new JsonSlurper()
def parsedJson = jsonSlurper.parseText(responseBodyTextFromTargetAPI);

parsedJson.data.each { object ->  	   
  	String valueJson = templateJson;	  
	valueJson = valueJson.replace("#mat_id" , ""+object.id );	
...
GROOVY

JsonTemplate string kullanarak veri içinden for ile tüm json üzerinden JsonPath ile çekerek

Performans: 20sn

import  tr.com.soagen.apinizer.util.*;
 
int itemCount = 0;

try{
	itemCount= UtilJsonOperations.extractFromJsonBody(null, responseBodyTextFromTargetAPI, '$'+".data.length()").toInteger();
}catch(Exception e){
  ...
}
String templateJson = "{"+
"\"mat_id\":\"#mat_id\",	"+
...
"}";
 

for(int i=0; i < itemCount; i++){
  	String valueJson = templateJson;
	String jsonPath  ='$'+".data["+i+"].id";  
	String value  = UtilJsonOperations.extractFromJsonBody(null, responseBodyTextFromTargetAPI, jsonPath)
	valueJson = valueJson.replace("#mat_id" , value );
...
GROOVY


JsonTemplate string kullanarak veri içinden for ile partial json üzerinden JsonPath ile çekerek

Performans: 40 sn (En kötüsü)

import  tr.com.soagen.apinizer.util.*;
 
int itemCount = 0;

try{
	itemCount= UtilJsonOperations.extractFromJsonBody(null, responseBodyTextFromTargetAPI, '$'+".data.length()").toInteger();
}catch(Exception e){
  ...
}
String templateJson = "{"+
"\"mat_id\":\"#mat_id\",	"+
...
"}";
 

for(int i=0; i < itemCount; i++){
  	String valueJson = templateJson;	   
	String partialValue  = UtilJsonOperations.extractFromJsonBody(null, responseBodyTextFromTargetAPI, '$'+".data["+i+"]")    
	String jsonPath  ='$'+".id";  
	String value  = UtilJsonOperations.extractFromJsonBody(null, partialValue, jsonPath)
	valueJson = valueJson.replace("#mat_id" , value );
...
GROOVY