Apama 10.3 | Apama Documentation | Developing Apama Applications | Developing Apama Applications in EPL | Using EPL Plug-ins | Using the JSON plug-in
Using the JSON plug-in
You can use the JSON plug-in to convert EPL objects to JSON strings, and vice versa. When converting from JSON strings, JSON objects are converted to dictionary<any, any> and JSON lists are converted to sequence<any>.
To use the JSON plug-in, add the JSON Support EPL bundle to your Apama project in Software AG Designer. For details, see Adding EPL bundles to projects.
The JSON plug-in is provided as a JSONPlugin event in the com.apama.json package. The JSONPlugin event provides the following actions:
*To convert a JSON string to an EPL object:
fromJSON(string) returns any
*To convert an EPL object (including events, dictionaries and sequences) to a JSON string:
toJSON(any) returns string
For detailed information, see the API Reference for EPL (ApamaDoc) .
The following is a simple example:
using com.apama.json.JSONPlugin;
event Address {
integer houseNumber;
sequence<string> address;
optional<string> postcode;
monitor PrintJSON {
action onload() {
Address a1 := new Address;
Address a2 := new Address;
a1.houseNumber := 107;
a1.address.append("The Rounds");
a1.postcode := "CB1 2AB";
a2.houseNumber := 196;
a2.address.append("Exeter Road");
print JSONPlugin.toJSON(a1);
print JSONPlugin.toJSON(a2);
The above example prints the following:
{"postcode":"CB1 2AB","address":["The Rounds","Milton"],"houseNumber":107}
{"postcode":null,"address":["Exeter Road","Newmarket"],"houseNumber":196}
Equivalent functionality is available with the JSON codec connectivity plug-in. Use the JSON codec if the JSON is coming in as an entire message of a connectivity chain. Using a codec helps to separate the application logic from the connection over which the data is being sent, and allows the use of mapping codecs if needed. See The JSON codec connectivity plug-in for detailed information.
Use the JSON EPL plug-in if only one field of an event is JSON, or if the events are going to or are coming from a connection that is not using a connectivity chain.

Copyright © 2013-2018 | Software AG, Darmstadt, Germany and/or Software AG USA, Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors.