HomeGuidesAPI Reference
Submit Documentation FeedbackJoin Developer CommunityOptimizely GitHubOptimizely NuGetLog In


Since statically typed languages lack native support for JSON, the Java SDK uses the OptimizelyJSON object to retrieve JSON in a flexible way. The Get All Feature Variables and Get Feature Variable Json methods use OptimizelyJSON to return feature variables. For more information, see [Get All Feature Variables](🔗) and [Get Feature Variable](🔗).

## Version

SDK v3.5 and higher

## Methods

You can access JSON representations with the following methods:

MethodParametersDescription
`toString`noneReturns a string representation of the JSON object
`toMap`noneReturns a map representation of the JSON object: `(Map<String,Object>)`
`getValue``String jsonKey, Class<T> clazz`Returns a specified schema object (`T`) with the key/value pair of the JSON key you pass to this method. If JSON key is null or empty, it populates your schema object with all JSON key/value pairs. You can retrieve information for a nested member of the JSON data structure by using flattened JSON dot notation. For example, if you want to access the key `nestedField` in `{field1: {nestedField: "blah"}}`, you can call `getValue` with the parameter `"field1.nestedField2"`.

The OptimizelyJSON object is defined as follows:





## Examples

You can easily use `OptimizelyJSON` object, for example to:

  • Get a JSON string by calling the `toString` method, or

  • Retrieve a specified schema from the `OptimizelyJSON` object by calling the `getValue` method.

The following example shows how to use an OptimizelyJSON object to populate a schema object you declare.