JSON cookie format reference
A list of the items to be found in a JSON-formatted cookie, as produced by the (custom) serializer of Claims. This topic also explains how the various JSON values are deserialized on the receiving end.
Property-value pairs
Write a property-value pair as follows:
"propertyname":value,
where propertyname is a simple string, and value is determined by the data type of the value. The last property-value pair does not need a comma at the end.
The collection of all property-value pairs is enclosed in an opening curly brace ({) and closing curly brace (}).
For example, this JSON cookie contains two properties, one an integer, and another a string:
{
"integerproperty":42,
"stringproperty":"foo"
}
String values
Write a property-value with a value of type string as follows:
"propertyname":"stringvalue",
where propertyname and stringvalue are both simple strings.
For example:
"stringproperty":"foo",
Integer values
Write a property-value with a value of type integer as follows:
"propertyname":N,
where propertyname is a simple string, and N is any whole number with less precision than a long.
For example:
"atltuae":42,
Long values
Write a property-value with a value of type long as follows:
"propertyname":N,
where propertyname is a simple string, and N is any whole number.
For example:
"nationaldebt":15781909756690,
Deserialization: A long will be deserialized if it can be identified as such, that is, if it is so large that it cannot be an integer. If you serialize a long value that is small enough to be an integer, it will be deserialized to an integer, and you have to explicitly cast it to long after deserialization.
Float values
Write a property-value with a value of type float as follows:
"propertyname":N.M,
where propertyname is a simple string, and N.M is any decimal value with less precision than a double.
For example:
"average":4.37,
Deserialization: A float will be deserialized if it can be identified as such, that is, if it has a fractional part with less precision than a double, and more precision than an integer. You can prevent floats that are whole numbers from being deserialized as integers by explicitly adding a .0 fractional part:
"number":6will be deserialized to an integer"number":6.0will be deserialized to a float
Double values
Write a property-value with a value of type double as follows:
"propertyname":N.M,
where propertyname is a simple string, and N.M is a decimal value written with double float precision.
For example:
"average":4.37435234634656,
Deserialization: A double will be deserialized if it can be identified as such, that is, if it has a fractional part with more precision than a float. You can prevent doubles that are whole numbers from being deserialized as integers by explicitly adding a .00000000000000000 fractional part:
"number":6will be deserialized to an integer"number":6.0will be deserialized to a float"number":6.000000000000000000will be deserialized to a double
Boolean values
Write a property-value with a value of type Boolean as follows:
"propertyname":truthvalue,
where propertyname is a simple string, and truthvalue is either true or false.
For example:
"newcustomer":true,
(Resizable) array values
Write a property-value with a value of type array or resizable array as follows:
"propertyname":[value1,value2],
where propertyname is a simple string, and value1, value2 and so on are each values themselves.
For example, this is an array of strings:
"strarr":["Tom","Dick","Harry"],
This is an array of integers:
"intarr":[6,2,3],
This is an array of doubles:
"doublearr":[6.2,2.75,3.11],
This is an array of Booleans:
"boolarr":[true,true,false],
This is an array of arrays of strings:
"strarrarr":[
["foo","bar"],
["fred","quux"]
],
This is an array of maps:
"maparr":[
{
"netherlands":"amsterdam",
"france":"paris",
"germany":"berlin"
},
{
"apples":45,
"oranges":5
}
],
- When deserializing in Java, a JSON array is deserialized to an
ArrayListobject. - When deserializing in .NET, a JSON array is deserialized to a
Listobject.
If you serialized a simple array, your deserialized output will be an ArrayList or List object. To get your original array back, use the .toArray or .ToArray method, respectively .
Map values
Write a property-value with a value of type map as follows:
"propertyname":
{
"key1":"value1",
"key2":"value2"
},
where propertyname and key1, key2 and so on are simple strings, and value1, value2 and so on are each values themselves. That is, the value of the map (the curly braces and their contents) has the same format as the JSON cookie itself.
For example, this is a map of property-value pairs with strings as values:
"countrycapitalsmap":
{
"netherlands":"amsterdam",
"france":"paris",
"germany":"berlin"
}
This is a map of property-value pairs with integers as values:
"countrypopulationmap":
{
"netherlands":16847007,
"france":65350000,
"germany":81799600
}
This is a map of property-value pairs with doubles as values:
"countrypopulationdensitymap":
{
"netherlands":404.2,
"france":116.7,
"germany":229.3
}
This is a map of property-value pairs with Booleans as values:
"countrymonarchymap":
{
"netherlands":true,
"france":false,
"germany":false
}
This is a map of property-value pairs with arrays of strings as values:
"countrycommonmalenamesmap":
{
"netherlands":["Henk","Dirk","Kees"],
"france":["Jean","Alain","Pierre"],
"germany":["Heinz","Fritz","Hans"]
}
Deserialization: A map of property-value pairs is deserialized to a HashMap (Java deserialization) or a Dictionary (.NET deserialization) .
Example cookie
The following example JSON cookie shows most of the above data types:
{
"doublearraylist":[1.1,2.2,3.3],
"mapstringstring":
{
"key3":"value3",
"key2":"value2",
"key1":"value1"
},
"int":1,
"intarraylist":[1,2,3],
"string":"stringvalue",
"boolean":true,
"map_string_arrayliststring":
{
"key2":["value2.1","value2.2","value2.3"],
"key1":["value1.1","value1.2","value1.3"]
},
"booleanarraylist":[true,false,true],
"double":1.0,
"stringarraylist":["stringarraylistvalue1","stringarraylistvalue2","stringarraylistvalue3"]
}