Conversion Between JSON and Siebel Property Sets

This topic helps you understand that the Siebel XSL to XML converter business service has two methods for converting Siebel property sets to JSON and back.

You can convert Siebel Property Sets to JSON and JSON to Siebel Property Sets using the Siebel XSL To XML Convertor Business Service. The Business Service has two methods for this purpose.

  • pstojson – Converts a Siebel Property Set to JSON.
  • jsontops – Converts JSON to a Siebel Property Set.

To convert a Siebel Property Set to a JSON string there are a few rules.

Array of objects

If a set of properties in a Siebel Property Set should become a JSON array, first create a parent Property Set. The parent will contain all the child Property Sets and is the array’s container. The parent Property Set has a Type with the “ListOf” prefix. After ListOf you specify the type of objects that will exist in the array. For instance, if you're going to have a list of Truck objects, the parent Property Set will have a Type of “ListOfTruck”. Each child Property Set that will be added to the parent Property Set will have a Type of “Truck”. The Business Service looks for the Property Sets with the Type that matches the ListOf<type> in its parent. In the below example where we want an array of Cars, the Type of the Property Set (Parent) containing the instances of Cars has the Type: ListOfCars, its child Property Sets will have the type “Cars”. Similarly, the array of Trucks has the Type ListOfTrucks its child Property Sets will have the type “Trucks”. Each instance of a car or truck will be its own Property Set with the Type of Cars or Trucks.

Arrays of primitives

The Type of a Property Set that's meant to hold all the values of a primitive array has this format: “ListOf<your type>__Primitive”. There are two consecutive underscores before the word Primitive. The child Property Sets would then have a type matching <your type>. For example, if I've a Property Set with the Type ListOfTyres__Primitive, its child Property Sets will have the type “Tyres”.

Each child Property Set will contain one and only one property which is the primitive value. To add another primitive value as a property, create one more child Property Set with type <your type> (Tires, for example) and add a property within it with its primitive value. Their property names are in the format below. (The default type is string.)

Note: Within an array, the property should be of same data type and can't have mixed types. For example, the array can be of only integers, but can't be of strings and integers.

The following example represents a primitive array of type integer. This is converted to JSON as

{Tires : [4,5,6] }

Note the prefix “ListOf” and the suffix “__Primitive” of the parent Property Set. Also note that each child Property Set has type same as parent but without the prefix and suffix. Each has only one property named as elem_und_undvalue which is prefixed with the data type (integer) that this array should contain. Here _und means “underscore”. There are two consecutive underscores before the string “value” in each element.

<ListOfTires__Primitive >
					<Tires integer_elem_und_undvalue="4"/>
					<Tires integer_elem_und_undvalue="5"/>
					<Tires integer_elem_und_undvalue="6"/>
				</ListOfTires>

Skipping a particular Property Set

If a Property Set in the hierarchy isn't valid, you can explicitly skip it by using the __SKIP__WRAPPER suffix. Note there are two consecutive underscores before the word SKIP and before the word WRAPPER. For example, if you've got a Property Set of Type Cars and want to skip that Property Set you'd set the Type to Cars__SKIP__WRAPPER.

These Property Sets are added to their parent and passed to the Siebel XSL To XML Convertor Business Service to get the result.

Note: The conversion doesn't maintain the order from Property Set to JSON nor from JSON to Property Set.

Example - to convert a Siebel property set to JSON

function convertPSToJSON(outputs:PropertySet)
{
    var lPS_convertMeToJSON:PropertySet	= TheApplication().NewPropertySet();
    var lPS_Automobiles:PropertySet       		= TheApplication().NewPropertySet();
    var lPS_listOfTrucks:PropertySet      		= TheApplication().NewPropertySet();
    var lPS_truckOne:PropertySet          		= TheApplication().NewPropertySet();
    var lPS_truckTwo:PropertySet          		= TheApplication().NewPropertySet();
    var lPS_listOfCars:PropertySet        		= TheApplication().NewPropertySet();
    var lPS_carOne:PropertySet            		= TheApplication().NewPropertySet();
    var lPS_carTwo:PropertySet            		= TheApplication().NewPropertySet();
       
    var lPS_output:PropertySet            		= TheApplication().NewPropertySet();;
    var lBS_converter:Service             		= TheApplication().GetService("Siebel XSL To XML Convertor");

    var lPS_ListOfTyresIntPrimitive       		= TheApplication().NewPropertySet();
    var lPS_TyresInt                      			= TheApplication().NewPropertySet();
    var lPS_ListOfTyresStr1Primitive      		= TheApplication().NewPropertySet();
    var lPS_TyresStr1                     			= TheApplication().NewPropertySet();
    var lPS_ListOfTyresStr2Primitive      		= TheApplication().NewPropertySet();
    var lPS_TyresStr2                     			= TheApplication().NewPropertySet();
    var lPS_ListOfTyresStr3Primitive      		= TheApplication().NewPropertySet();
    var lPS_TyresStr3                     			= TheApplication().NewPropertySet();
       
     //set up the hierarchy.
    lPS_Automobiles.SetType("Automobiles");

    //ListOf is the string that tells the parser this will be an array of objects with Type = Trucks (or Cars)
    lPS_listOfTrucks.SetType("ListOfTrucks");
    lPS_listOfCars.SetType("ListOfCars");

    //These Property Sets with these specific types will be the members of the array of objects. They must have the same Type as their parent
    //Property Set with the “ListOf” prefix. The ListOfCars Property Set will look for a child Property Set with the Type “Cars”. 
    lPS_truckOne.SetType("Trucks");
    lPS_truckTwo.SetType("Trucks");
    lPS_carOne.SetType("Cars");
    lPS_carTwo.SetType("Cars");
   
    //This sets up primitive arrays. The ListOf<your type>__Primitive (note there are two underscores there) is the way to set the Type of these arrays.
    //Whatever you specify as <your type> is what you will use as the Type for child Property Sets.
    lPS_ListOfTyresIntPrimitive.SetType("ListOfTyres__Primitive");
    lPS_ListOfTyresStr1Primitive.SetType("ListOfTyres__Primitive");
    lPS_ListOfTyresStr2Primitive.SetType("ListOfTyres__Primitive");
    lPS_ListOfTyresStr3Primitive.SetType("ListOfTyres__Primitive");

    lPS_carOne.SetProperty("make","Tesla");
    lPS_carOne.SetProperty("Steering Wheel", "round");
    lPS_carOne.SetProperty("Seats", "five");
    lPS_carOne.SetProperty("Battery", "75KW");
    lPS_carOne.SetProperty("Frunk", "empty");
    
    //This is the actual array of the primitives. In this case they are strings so the property will have the following format.
    //string_elem__value (There are two consecutive underscores in the property name.)
    //The Type of this Property Set is the <your type> from the parent Property Set.
    lPS_TyresStr1                     = TheApplication().NewPropertySet();
    lPS_TyresStr1.SetType("Tyres");
    lPS_TyresStr1.SetProperty("string_elem__value", "four");

    //For each one of these primitive values, add the Property Set instance containing it to its parent Property Set.
    lPS_ListOfTyresStr1Primitive.AddChild(lPS_TyresStr1);

    //For each primitive value in the array, create a new Property Set instance and assign it a value. Then add it to the parent for
    //That type.
    lPS_TyresStr1                     = TheApplication().NewPropertySet();
    lPS_TyresStr1.SetType("Tyres");
    lPS_TyresStr1.SetProperty("string_elem__value", "five");
    lPS_ListOfTyresStr1Primitive.AddChild(lPS_TyresStr1);

    lPS_TyresStr1                     = TheApplication().NewPropertySet();
    lPS_TyresStr1.SetType("Tyres");
    lPS_TyresStr1.SetProperty("string_elem__value", "six");
    lPS_ListOfTyresStr1Primitive.AddChild(lPS_TyresStr1);

    //Once we have all the values for the array, add them to the car object.
    lPS_carOne.AddChild(lPS_ListOfTyresStr1Primitive);
     
    //add this to the parent array of cars.
    lPS_listOfCars.AddChild(lPS_carOne);

    //Do the same with the second instance of a car object.
    lPS_carTwo.SetProperty("make","Jeep");
    lPS_carTwo.SetProperty("Steering Wheel", "round");
    lPS_carTwo.SetProperty("Seats", "five");
    lPS_carTwo.SetProperty("GasTank", "20 Gal.");
    lPS_carTwo.SetProperty("Hood", "closed");
 
    //We are adding a single string to the array of primitives.
    lPS_TyresStr2                     = TheApplication().NewPropertySet();
    lPS_TyresStr2.SetType("Tyres");
    lPS_TyresStr2.SetProperty("string_elem__value", "five");
    lPS_ListOfTyresStr2Primitive.AddChild(lPS_TyresStr2);

    lPS_carTwo.AddChild(lPS_ListOfTyresStr2Primitive);
    
    lPS_listOfCars.AddChild(lPS_carTwo);

    //The cars have been handled, now do the same thing with trucks.
    lPS_truckOne.SetProperty("make","Ford");
    lPS_truckOne.SetProperty("Steering Wheel", "round");
    lPS_truckOne.SetProperty("Seats", "five");
    lPS_truckOne.SetProperty("GasTank", "20 Gal.");
    lPS_truckOne.SetProperty("Hood", "closed"); 

    lPS_TyresStr3                     = TheApplication().NewPropertySet();
    lPS_TyresStr3.SetType("Tyres");
    lPS_TyresStr3.SetProperty("string_elem__value", "six");
    lPS_ListOfTyresStr3Primitive.AddChild(lPS_TyresStr3);

    lPS_truckOne.AddChild(lPS_ListOfTyresStr3Primitive);

    lPS_listOfTrucks.AddChild(lPS_truckOne);    
     
    lPS_truckTwo.SetProperty("make","Rivian");
    lPS_truckTwo.SetProperty("Steering Wheel", "round");
    lPS_truckTwo.SetProperty("Seats", "six");
    lPS_truckTwo.SetProperty("Battery", "225KW");
    lPS_truckTwo.SetProperty("Hood", "closed");

    //The second Truck instance will have an array of integers, not strings.
    //Its property is “integer_elem__value”. There are two consecutive underscores in that property name.
    lPS_TyresInt                     = TheApplication().NewPropertySet();
    lPS_TyresInt.SetType("Tyres");
    lPS_TyresInt.SetProperty("integer_elem__value", "4");
    lPS_ListOfTyresIntPrimitive.AddChild(lPS_TyresInt);

    lPS_TyresInt                     = TheApplication().NewPropertySet();
    lPS_TyresInt.SetType("Tyres");
    lPS_TyresInt.SetProperty("integer_elem__value", "5");
    lPS_ListOfTyresIntPrimitive.AddChild(lPS_TyresInt);

    lPS_TyresInt                     = TheApplication().NewPropertySet();
    lPS_TyresInt.SetType("Tyres");
    lPS_TyresInt.SetProperty("integer_elem__value", "6");
    lPS_ListOfTyresIntPrimitive.AddChild(lPS_TyresInt);
    
    lPS_truckTwo.AddChild(lPS_ListOfTyresIntPrimitive);

    lPS_listOfTrucks.AddChild(lPS_truckTwo);   
     
    //Now the two arrays are added to the parent automobile array. The cars and trucks are both added here.
    lPS_Automobiles.AddChild(lPS_listOfCars);
    lPS_Automobiles.AddChild(lPS_listOfTrucks);
      
    //Finally, to process the entire hierarchy, add the automobiles to the top level Property Set. This is the one we pass
    //to the converter Business Service.
    lPS_convertMeToJSON.AddChild(lPS_Automobiles);
       
    //Convert this hierarchy to JSON. The result will be in the Value of the output Property Set.
    lBS_converter.InvokeMethod("pstojson",lPS_convertMeToJSON,lPS_output);
     
    //send back the output.
    Outputs.AddChild(lPS_output);

This is the JSON produced from this eScript.


JSON produced from the escript

Example - creating property sets from JSON

To create property sets from JSON, we can use the above output as a sample. We call the jsontops method of the Siebel XSL To XML Convertor business service and supply the JSON as the value for the input Property Set.

For example, when this json is input as the value for the input arguments in the Business Service Simulator in the Siebel client the output is shown below.

{"Automobiles":{"CarModels":["Jeep","Tesla"],"TruckModels":["Ford","Rivian"],"Cars":[{"make":"
Tesla","Steering
Wheel":"round","Tires":["four","five","six"],"Seats":"seven","Battery":"75KW","Hood":"closed"}
,{"make":"Jeep","Steering Wheel":"round","Tires":["five"],"Seats":"five","GasTank":"20
Gal.","Hood":"closed"}],"Trucks":[{"make":"Ford","Steering
Wheel":"round","Tires":["six"],"Seats":"five","GasTank":"20
Gal.","Hood":"closed"},{"make":"Rivian","Steering
Gal.","Hood":"closed"},{"make":"Rivian","Steering
Wheel":"round","Tires":[4,5,6],"Seats":"six","Battery":"225KW","Hood":"closed"}]}}

This is what's returned to the caller.

<?xml version="1.0" encoding="UTF-8"?><?Siebel-Property-Set EscapeNames="true"?>
<RespBody>
	<Automobiles>
		<ListOfTruckModels>
			<TruckModels elem_und_undvalue="Ford"/>
			<TruckModels elem_und_undvalue="Rivian"/>
		</ListOfTruckModels>
		<ListOfCarModels>
			<CarModels elem_und_undvalue="Jeep"/>
			<CarModels elem_und_undvalue="Tesla"/>
		</ListOfCarModels>
		<ListOfTrucks>
			<Trucks make="Rivian" Steering_spcWheel="round" Battery="225KW" Seats="six" Hood="closed">
				<ListOfTires>
					<Tires elem_und_undvalue="4"/>
					<Tires elem_und_undvalue="5"/>
					<Tires elem_und_undvalue="6"/>
				</ListOfTires>
			</Trucks>
			<Trucks make="Ford" GasTank="20 Gal." Steering_spcWheel="round" Seats="five" Hood="closed">
				<ListOfTires>
					<Tires elem_und_undvalue="six"/>
				</ListOfTires>
			</Trucks>
		</ListOfTrucks>
		<ListOfCars>
			<Cars make="Jeep" GasTank="20 Gal." Steering_spcWheel="round" Seats="five" Hood="closed">
				<ListOfTires>
					<Tires elem_und_undvalue="five"/>
				</ListOfTires>
			</Cars>
			<Cars make="Tesla" Steering_spcWheel="round" Battery="75KW" Seats="seven" Hood="closed">
				<ListOfTires>
					<Tires elem_und_undvalue="four"/>
					<Tires elem_und_undvalue="five"/>
					<Tires elem_und_undvalue="six"/>
				</ListOfTires>
			</Cars>
		</ListOfCars>
	</Automobiles>
</RespBody>