JsonP (javax.json) Sample

The JsonPSample sample contains a simple web application, jsonp.war, which illustrates use of the Liberty jsonp-1.0 feature. When present, this feature enables the javax.json classes introduced as part of the Java EE 7 specification. These provide Java interfaces and factories for parsing, manipulating, and saving data in JavaScript Object Notation (JSON) form.

It is expected that use of the JsonP API will largely replace use of IBM's JSON4J classes, which were an earlier set of java tools for this purpose... but the two differ enough that it's possible both will remain in use.

Currently supported demonstrations:

  • An introductory "home page", which is served as /jsonp. It's essentially the same as this text, but has live links to each of the examples.
  • Simple parse of JSON, check a few values, and regenerate the JSON: /jsonp/parseCheckSerialize
  • Programmatically construct a simple JSON object /jsonp/build
  • Programmatically constructing a JSON List of Objects: /jsonp/buildDeepList

And just for fun, toy routines to convert between JSON and JinX (an ad-hoc "JSON in XML" syntax). This demonstrates both tree-walking the JSON model and more complicated programmatic construction.

  • Convert the JSON List of Objects into JinX form: /jsonp/jsonToJinx
  • Convert the JinX representation back into JSON: /jsonp/jinxToJson

This sample can be installed onto runtime versions and later.

Installation Instructions

Online installation (requires or later):

  1. Install the sample by running the command below from the bin directory of your server installation:
    installUtility install JsonPSample

Any missing features required by the server will be installed for you.

Offline installation:

  1. Download the JsonPSample.jar using the download button at the top of the page and place it in the root of your server installation.
  2. Extract the sample into the Liberty installation by running the command below from the root of your server installation:
    java -jar JsonPSample.jar

Any missing features required by the server will need to be installed separately.

Running The Application

To run the jsonp application:

  1. Start the JsonPSample server by running the command below from the bin directory in the Liberty profile installation:
    server run JsonPSample
  2. Confirm the application started by looking for the following message in the log:
    CWWKZ0001I: Application jsonp started in XX.XX seconds.
  3. In your browser, enter the URL for the application: http://localhost:9147/jsonp/ (where port 9147 assumes the httpEndpoint provided in the sample server.xml has not been modified).
  4. In your browser, you should see the message
    JsonP Servlet - Basic demonstration of JSR353 (JSON Processing) support.
    followed by an introductory page describing the examples and providing links to each of them. To return to this "home page", click the
    Return to /jsonp menu
    link at the bottom of each of these pages.


The jsonp.war file contains the source and binaries for the application, and can be used to import it to Eclipse.

The application is automatically installed because it is located in the server dropins directory. Any number of applications can be installed from this location.

Sample Structure

  • wlp
    • usr
      • servers
        • JsonPSample
          • Copyright.txt
          • dropins
            • jsonp.war
          • readme.html
          • server.xml