PeterO.Cbor.JSONOptions
## PeterO.Cbor.JSONOptions
public sealed class JSONOptions
Includes options to control how CBOR objects are converted to and from JavaScript Object Notation (JSON).
Member Summary
[AllowDuplicateKeys](#AllowDuplicateKeys)
- Gets a value indicating whether to allow duplicate keys when reading JSON.[Base64Padding](#Base64Padding)
- Deprecated: This property now has no effect. This library now includes necessary padding when writing traditional base64 to JSON and includes no padding when writing base64url to JSON, in accordance with the revision of the CBOR specification.[public static readonly PeterO.Cbor.JSONOptions Default;](#Default)
- The default options for converting CBOR objects to JSON.[KeepKeyOrder](#KeepKeyOrder)
- Gets a value indicating whether to preserve the order in which a map’s keys appear when decoding JSON, by using maps created as though by CBORObject.[NumberConversion](#NumberConversion)
- Gets a value indicating how JSON numbers are decoded to CBOR objects.[PreserveNegativeZero](#PreserveNegativeZero)
- Gets a value indicating whether the JSON decoder should preserve the distinction between positive zero and negative zero when the decoder decodes JSON to a floating-point number format that makes this distinction.[ReplaceSurrogates](#ReplaceSurrogates)
- Gets a value indicating whether surrogate code points not part of a surrogate pair (which consists of two consecutive char s forming one Unicode code point) are each replaced with a replacement character (U+FFFD).[ToString()](#ToString)
- Gets the values of this options object’s properties in text form.[WriteBasic](#WriteBasic)
- Gets a value indicating whether JSON is written using only code points from the Basic Latin block (U+0000 to U+007F), also known as ASCII.
public JSONOptions( bool base64Padding);
Deprecated. Use the more readable string constructor instead.
Initializes a new instance of the PeterO.Cbor.JSONOptions class with the given value for the Base64Padding option.
Parameters:
- base64Padding: Whether padding is included when writing data in base64url or traditional base64 format to JSON.
public JSONOptions( bool base64Padding, bool replaceSurrogates);
Deprecated. Use the more readable string constructor instead.
Initializes a new instance of the PeterO.Cbor.JSONOptions class with the given values for the options.
Parameters:
-
base64Padding: Whether padding is included when writing data in base64url or traditional base64 format to JSON.
-
replaceSurrogates: Whether surrogate code points not part of a surrogate pair (which consists of two consecutive
char
s forming one Unicode code point) are each replaced with a replacement character (U+FFFD). The default is false; an exception is thrown when such code points are encountered.
public JSONOptions( string paramString);
Initializes a new instance of the PeterO.Cbor.JSONOptions class.
Parameters:
- paramString: A string setting forth the options to use. This is a semicolon-separated list of options, each of which has a key and a value separated by an equal sign (“=”). Whitespace and line separators are not allowed to appear between the semicolons or between the equal signs, nor may the string begin or end with whitespace. The string can be empty, but cannot be null. The following is an example of this parameter:
base64padding=false;replacesurrogates=true
. The key can be any one of the following where the letters can be any combination of basic uppercase and/or basic lowercase letters:base64padding
,replacesurrogates
,allowduplicatekeys
,preservenegativezero
,numberconversion
,writebasic
,keepkeyorder
. Other keys are ignored in this version of the CBOR library. (Keys are compared using a basic case-insensitive comparison, in which two strings are equal if they match after converting the basic uppercase letters A to Z (U+0041 to U+005A) in both strings to basic lowercase letters.) If two or more key/value pairs have equal keys (in a basic case-insensitive comparison), the value given for the last such key is used. The first four keys just given can have a value of1
,true
,yes
, oron
(where the letters can be any combination of basic uppercase and/or basic lowercase letters), which means true, and any other value meaning false. The last key,numberconversion
, can have a value of any name given in theJSONOptions.ConversionMode
enumeration (where the letters can be any combination of basic uppercase and/or basic lowercase letters), and any other value is unrecognized. (If thenumberconversion
key is not given, its value is treated asfull
. If that key is given, but has an unrecognized value, an exception is thrown.) For example,base64padding=Yes
andbase64padding=1
both set theBase64Padding
property to true, andnumberconversion=double
sets theNumberConversion
property toConversionMode.Double
.
Exceptions:
-
System.ArgumentNullException: The parameter paramString is null. In the future, this class may allow other keys to store other kinds of values, not just true or false.
-
System.ArgumentException: An unrecognized value for
numberconversion
was given.
public JSONOptions();
Initializes a new instance of the PeterO.Cbor.JSONOptions class with default options.
public static readonly PeterO.Cbor.JSONOptions Default;
The default options for converting CBOR objects to JSON.
public bool AllowDuplicateKeys { get; }
Gets a value indicating whether to allow duplicate keys when reading JSON. Used only when decoding JSON. If this property is true
and a JSON object has two or more values with the same key, the last value of that key set forth in the JSON object is taken.
Returns:
A value indicating whether to allow duplicate keys when reading JSON. The default is false.
public bool Base64Padding { get; }
Deprecated. This property now has no effect. This library now includes necessary padding when writing traditional base64 to JSON and includes no padding when writing base64url to JSON, in accordance with the revision of the CBOR specification.
Gets a value indicating whether the Base64Padding property is true. This property has no effect; in previous versions, this property meant that padding was written out when writing base64url or traditional base64 to JSON.
Returns:
A value indicating whether the Base64Padding property is true.
public bool KeepKeyOrder { get; }
Gets a value indicating whether to preserve the order in which a map’s keys appear when decoding JSON, by using maps created as though by CBORObject.NewOrderedMap. If false, key order is not guaranteed to be preserved when decoding JSON.
Returns:
A value indicating whether to preserve the order in which a CBOR map’s keys appear when decoding JSON. The default is false.
public PeterO.Cbor.JSONOptions.ConversionMode NumberConversion { get; }
Gets a value indicating how JSON numbers are decoded to CBOR objects. None of the conversion modes affects how CBOR objects are later encoded (such as via EncodeToBytes
).
Returns:
A value indicating how JSON numbers are decoded to CBOR. The default is ConversionMode.Full
.
public bool PreserveNegativeZero { get; }
Gets a value indicating whether the JSON decoder should preserve the distinction between positive zero and negative zero when the decoder decodes JSON to a floating-point number format that makes this distinction. For a value of false
, if the result of parsing a JSON string would be a floating-point negative zero, that result is a positive zero instead. (Note that this property has no effect for conversion kind IntOrFloatFromDouble
, where floating-point zeros are not possible.).
Returns:
A value indicating whether to preserve the distinction between positive zero and negative zero when decoding JSON. The default is true.
public bool ReplaceSurrogates { get; }
Gets a value indicating whether surrogate code points not part of a surrogate pair (which consists of two consecutive char
s forming one Unicode code point) are each replaced with a replacement character (U+FFFD). If false, an exception is thrown when such code points are encountered.
Returns:
True, if surrogate code points not part of a surrogate pair are each replaced with a replacement character, or false if an exception is thrown when such code points are encountered. The default is false.
public bool WriteBasic { get; }
Gets a value indicating whether JSON is written using only code points from the Basic Latin block (U+0000 to U+007F), also known as ASCII.
Returns:
A value indicating whether JSON is written using only code points from the Basic Latin block (U+0000 to U+007F), also known as ASCII. Default is false.
public override string ToString();
Gets the values of this options object’s properties in text form.
Return Value:
A text string containing the values of this options object’s properties. The format of the string is the same as the one described in the String constructor for this class.