Overview

Welcome to PruTAN's Transformer Rules page! Here, you'll delve into the world of data transformation and learn how implementing Transformer Rules can elevate your API environment creation and testing experience.

PruTAN's Transformer supports multiple data formats, including JSON, XML, and ISO 8583. By leveraging Transformer Rules, users can create scripts that modify data on-the-fly, applying conditional logic to handle various scenarios.

By exploring this page, you'll gain valuable insights into:

Understanding Data Transformation: Learn the fundamentals of data transformation and how Transformer Rules enable dynamic modification of data payloads.

Practical Examples: Dive into real-world examples showcasing how Transformer Rules can be applied to different data formats such as JSON, XML, and ISO 8583.

Rule Implementation: Explore the process of accessing and setting rules for each data format, empowering you to tailor your data transformations with precision.

Transformer Structure :

We get predefined URL : Ex. https://dev-app.prutan.com/prutan/TF/d1380131-3a4c-4ff9-9903-038a90e5237a ;
or endpoint & port : Ex. dev-app.prutan.com:8001

There are three-tabs present : L1, L2 & L3;

  • In L1 tab: There are two body and content type. Incoming Request Body and Outgoing Response Body
  • In L2 tab:
    There are two rules body. Request Rules and Response Rules
  • In L3 tab: There are two body, request field(URL/endpoint:port) and content type for client details. Client Request Body and Client Response Body
    Rules:

L1 Content type – application/json

L3 Content type – application/iso

JSON

Content type – application/json


Rule
Ex:  l3.set("38”, l1.get("bankaccount.security.otp"));

L1 Body
{
 "bankaccount": {
   "security": {
     "username": "raju095",
     "otp": "213293"
   }
 }
}
    L3 Body
<isomsg>
 <header />
 <field id="0" value="0210" />
 <field id="2" value="4659460000000004" />
 <field id="3" value="210000" />
 <field id="49" value="826" />
</isomsg>

L3 Body after rules
<isomsg>
    <header />
    <field id="0" value="0210" />
    <field id="2" value="4659460000000004" />
    <field id="3" value="210000" />
    <field id="49" value="826" />
    <field id="38" value="213293" />
</isomsg>

XML

Content type – application/xml


<?xml version = "1.0"?>
<class>
        <student rollno ="393">
               <firstname>Dinkar</firstname>
               <lastname>Mishra</lastname>
               <nickname>Don</nickname>
               <marks>85</marks>
         </student>
         <student rollno ="300">
               <firstname>Piyush</firstname>
               <lastname>Jani</lastname>
               <nickname>PJ</nickname>
                <marks>77</marks>
         </student>
</class>

    Get rules
l1.get("class.student[@rollno='393'].firstname") = /class/student[@rollno='393']/firstname/text()  Ans: Dinkar
l1.get("class.student[1].lastname") = /class/student[1]/lastname/text() 
Ans: Mishra
l1.get("class.student[2].firstname") = /class/student[2]/firstname/text() 
Ans: Piyush
l1.get("class.student[2].@rollno") = /class/student[2]/@rollno 
Ans: 300
    Set rules
l1.set("class.student[1].firstname","umang") = /class/student[1]/firstname/text() 
// set student firstname = Umang in first node
l1.set("class.student[2].@rollno","301") = /class/student[2]/@rollno 
// set student attribute 301  in second node
l1.set("class.student[3].@rollno", "302") = /class/student[3]/@rollno 
// create student age in second node
l1.set("class.student.firstname, "Gaurav") = /class/student[3]/firstname 
// create student age in second node
l1.set("class.student[3].lastname, "Modi") = /class/student[2] 
// create student age in second node
l1.set("class.student[3].nickname, "GK") = /class/student[2] 
// create student age in second node
l1.set("class.student[3].marks, "50") = /class/student[2] 
// create student age in second node



Body after rule
<?xml version="1.0" encoding="UTF-8"?>
<class>
   <student rollno="393">
      <firstname>Umang</firstname>
      <lastname>Mishra</lastname>
      <nickname>Don</nickname>
      <marks>85</marks>
   </student>
   <student rollno="301">
      <firstname>Piyush</firstname>
      <lastname>Jani</lastname>
      <nickname>PJ</nickname>
      <marks>77</marks>  
       <age>21</age>
  </student>
  <student rollno="302">
      <firstname>Gaurav</firstname>
      <lastname>Modi</lastname>
      <nickname>GK</nickname>
      <marks>50</marks>
   </student>
</class>
<school>
         <name>JL HS<name>
<school>

ISO

Content type – application /iso


<isomsg>
  <header/>
  <field id="0" value="0200"/>
  <field id="2" value="4659460000000004"/>
  <field id="11" value="987654"/>
  <field id="41" value="T2468135"/>
</isomsg>

    Get rules
l1.get("41")     // get 41 No id value
Ans: T2468135
    Set rules
l1.set("3","210000")
Body after rule
<isomsg>
  <header/>
  <field id="0" value="0200"/>
  <field id="2" value="4659460000000004"/>
  <field id="3" value="210000"/>
  <field id="11" value="987654"/>
  <field id="41" value="T2468135"/>
</isomsg>
 
    JSON
Content type – application/json

{
    "school": {
        "class": {
            "student": "Raj"
        }
    }
}

    Get rules
l1.get("school.class.student ")
Ans: Raj
    Set rules
l1.set("school.class.rollNo","21")
l1.set("school.class.marks[0].subject","Maths");
l1.set("school.class.marks[0].score","45");
l1.set("school.class.marks[1].subject","Science");
l1.set("school.class.marks[1].score","41");

After rule body
{
    "school": {
        "class": {
            "student": "Raj",
            "rollNo": "21",
            "marks": [{
                    "subject": "Maths",
                    "score": 45
                }, {
                    "subject": "Science",
                    "score": 41
                }
            ]
        }
    }
}

Transforming data is at the core of modern API ecosystems. By mastering Transformer Rules, you'll unlock the full potential of your API environment, streamlining integration processes, and enhancing testing experiences. Dive into the world of data transformation with PruTAN's Transformer Rules and elevate your API journey today!