Class

JSONOptions

JSO


Description

Contains properties to set up the Compact, DecimalPlaces, and IndentSpacing options for use with JSONItem.ToString and GenerateJSON.

Properties

Name

Type

Read-Only

Shared

Compact

Boolean

DecimalPlaces

Integer

IndentSpacing

Integer

Property descriptions


JSONOptions.Compact

Compact As Boolean

When getting the String representation of a JSONItem using the ToString method, setting this property to True (the default) will remove unnecessary whitespace from the resulting string. A value of False will result in a string with SPACEs and EndOfLines embedded to make the string more readable.

This example sets Compact to True before calling ToString.

Var person As New JSONItem
' This object is manipulated like a dictionary
person.Value("Name") = "John Doe"
person.Value("Age") = 32
person.Value("Married") = True
person.Value("Spouse") = "Jane Doe"

Var kids As New JSONItem
' This object is manipulated like an array
kids.Add("John Jr")
kids.Add("Jamie")
kids.Add("Jack")
kids.Add("Josie")
kids.AddAt(0,"Jonah")
kids.RemoveAt(2)
person.Value("Kids") = kids

Var options As New JSONOptions
options.Compact = True

Var s As String = person.ToString(options)

JSONOptions.DecimalPlaces

DecimalPlaces As Integer

Controls the amount of decimal places for numbers when you call the ToString function.


JSONOptions.IndentSpacing

IndentSpacing As Integer

Controls the amount of spaces used for intending when you call the ToString function. The default is 4.

Sample code

In this example, a JSONItem with the name “product” is created and displayed in a MessageBox. The JSON string is formatted according to the set options:

Var product As New JSONItem
product.Value("Name") = "Chewing gum"
product.Value("Price") = 1.50
product.Value("Weight") = 0.5725

Var options As New JSONOptions
options.Compact = True
options.DecimalPlaces = 2
options.IndentSpacing = 8

MessageBox(product.ToString(options))

Compatibility

Project Types

All

Operating Systems

All

See also

Object parent class; JSONItem, GenerateJSON, ParseJSON methods; JSONException.