Add utils to support builder pattern for creating JSON objects.

This permits building JSON objects with a lot less casting (or temporary
variables).

Updated example Java apps to show how the builder can be used.