Tivoli Directory Integrator, Version 7.1.1

JSON Parser

The JSON Parser reads and writes entries using the JavaScript Object Notation (JSON) format.

JSON is a lightweight data-interchange format and a subset of JavaScript programming language. JSON is built using the following two structures:

For detailed information about JSON format, see http://json.org.

Using the Parser

The JSON parser reads and writes JSON formatted data. The JSON framework of IBM JavaScript Engine is used for mapping Java objects and JSON objects. The JsonFactory instance of JSON framework performs mapping between Tivoli Directory Integrator Entry or Attribute objects and basic JSON types such as object, string, array, number, or Boolean.

Mapping JSON types to Entry or Attribute
Objects
  • Objects are mapped to an Entry or Attribute. An Entry is used if the parent object is null. An Attribute is used if the parent object is not null. The topmost object in hierarchy is mapped to the Entry.
  • An Attribute based object contains named Attributes. Value of the parent object must be an Attribute and represents the property name and value of the object.
  • An Entry-based object contains named Attributes just as an Attribute based object does.
Arrays
  • Arrays are mapped to Attribute values. Values in the array are added as Attribute values to the current target.
  • An array, with values (for example, string, number, or Boolean) and objects, results in an Attribute with simple values and Attribute objects, which represents the unnamed objects in the array.
Mapping Entry or Attribute to JSON types
Entry
The Entry is mapped to an object and each Attribute represents a property in the object.
Attributes
An Attribute can be an array or an object. If an Attribute contains:
  • Both Attribute objects and other objects (for example, string, and date), the Attribute is an array.
  • Attribute objects, where all child Attributes have the same name, the Attribute is an array of objects.

The data mapping in JSON is symmetric. JSON data mapped in and written out produces the same result. However, the order of properties might not entirely match the data read.

Example

The following JSON data is an example, where simple values, arrays, and objects are nested.

{
	"id": "0001",
	"type": "donut",
	"name": "Cake",
	"ppu": 1.55,
	"batters":
		{
			"batter":
				[
					{ "id": "1001", "type": "Regular" },
					{ "id": "1002", "type": "Chocolate" },
					{ "id": "1003", "type": "Blueberry" },
					{ "id": "1004", "type": "Devil's Food" }
				]
		},
	"topping":
		[
			{ "id": "5001", "type": "None" },
			{ "id": "5002", "type": "Glazed" },
			{ "id": "5005", "type": "Sugar" },
			{ "id": "5007", "type": "Powdered Sugar" },
			{ "id": "5006", "type": "Chocolate with Sprinkles" },
			{ "id": "5003", "type": "Chocolate" },
			{ "id": "5004", "type": "Maple" }
		],
	"simplearray":
		[
			"first value",
			"second value",
			"third value"
		]
}

The above JSON data is mapped to the following Entry structure.

Entry.toDeltaString()

{
	"#type": "generic",
	"#count": 8,
	"batters": [
		"#type": "replace",
		"#count": 1,
		"#replace": ""batters": {
	"batter": {
		"batter": {
			"id": "1001",
			"type": "Regular"
		},
		"batter": {
			"id": "1002",
			"type": "Chocolate"
		},
		"batter": {
			"id": "1003",
			"type": "Blueberry"
		},
		"batter": {
			"id": "1004",
			"type": "Devil's Food"
		}
	}
}"
	],
	"id": [
		"#type": "replace",
		"#count": 1,
		"#replace": "0001"
	],
	"name": [
		"#type": "replace",
		"#count": 1,
		"#replace": "Cake"
	],
	"ppu": [
		"#type": "replace",
		"#count": 1,
		"#replace": 1.55
	],
	"topping": {
		"#type": "replace",
		"#count": 0,
		"topping": {
			"#type": "replace",
			"#count": 0,
			"id": [
				"#type": "replace",
				"#count": 1,
				"#replace": "5001"
			],
			"type": [
				"#type": "replace",
				"#count": 1,
				"#replace": "None"
			]
		},
		"topping": {
			"#type": "replace",
			"#count": 0,
			"id": [
				"#type": "replace",
				"#count": 1,
				"#replace": "5002"
			],
			"type": [
				"#type": "replace",
				"#count": 1,
				"#replace": "Glazed"
			]
		},
		"topping": {
			"#type": "replace",
			"#count": 0,
			"id": [
				"#type": "replace",
				"#count": 1,
				"#replace": "5005"
			],
			"type": [
				"#type": "replace",
				"#count": 1,
				"#replace": "Sugar"
			]
		},
		"topping": {
			"#type": "replace",
			"#count": 0,
			"id": [
				"#type": "replace",
				"#count": 1,
				"#replace": "5007"
			],
			"type": [
				"#type": "replace",
				"#count": 1,
				"#replace": "Powdered Sugar"
			]
		},
		"topping": {
			"#type": "replace",
			"#count": 0,
			"id": [
				"#type": "replace",
				"#count": 1,
				"#replace": "5006"
			],
			"type": [
				"#type": "replace",
				"#count": 1,
				"#replace": "Chocolate with Sprinkles"
			]
		},
		"topping": {
			"#type": "replace",
			"#count": 0,
			"id": [
				"#type": "replace",
				"#count": 1,
				"#replace": "5003"
			],
			"type": [
				"#type": "replace",
				"#count": 1,
				"#replace": "Chocolate"
			]
		},
		"topping": {
			"#type": "replace",
			"#count": 0,
			"id": [
				"#type": "replace",
				"#count": 1,
				"#replace": "5004"
			],
			"type": [
				"#type": "replace",
				"#count": 1,
				"#replace": "Maple"
			]
		}
	},
	"type": [
		"#type": "replace",
		"#count": 1,
		"#replace": "donut"
	],
	"simplearray": [
		"#type": "replace",
		"#count": 3,
		"#replace": "first value",
		"#replace": "second value",
		"#replace": "third value"
	]
}

Configuration

The JSON Parser has the following parameters:

Compact Output
Use this parameter to display data in compact mode. Compact mode writes JSON data on a single unformatted line and is the default mode.
Character Encoding
Use this parameter to specify the character encoding to be used when reading or writing data.
Detailed Log
Use this parameter to generate detailed log messages.
Comment
Use this parameter to add your comments. The comment is not considered while parsing data.
[ Top of Page | Previous Page | Next Page | Contents | Terms of use | Feedback ]
(C) Copyright IBM Corporation, 2003, 2012. All Rights Reserved.
IBM Tivoli Directory Integrator 7.1.1