<cOptions>.FromJSon

<< Click to Display Table of Contents >>

Navigation:  ThinBASIC Core Language > Data Structures > cOptions > cOptions Methods >

<cOptions>.FromJSon

 

Description

 

Initialize a cOptions object loading key/value pairs from a JSon string or file.

 

Syntax

 

<cOptions>.FromJSon( [FILE] sJSonString)

 

Returns

 

None

 

Parameters

 

Name

Type

Optional

Meaning

sJSonString

String

No

A string containing a JSon buffer

 

If FILE modifier is specified, sJSonString is considered a file name whose content will be automatically loaded.

 

Remarks

 

Attention: cOptions object will be erased before parsing new KeyName/Value pairs. All KeyName/Value pairs inside the object will be removed

 

Insert thinBasic code inside a key Value

 

It is possible to specify thinBasic code inside a JSon Value. If a value starts with $( and ends with ) it will be considered thinBasic code and interpreted in the fly.

 

Example: in the following JSon string Filename, RecordSeparator and StringDelimiter values are all included between $( and ) so they will be interpreted as thinBasic code and interpreted on the fly when <cOptions>.FromJSon will load them:

 

{
  "Filename": "$({APP_SourcePath + \"ADODB_Test_Export_Out.csv\"})",
  "AppendToFile": false,
  "ColumnNames": true,
  "RecordSeparator": "$({$crlf})",
  "StringDelimiter": "$({$dq})",
  "DecimalSeparator": ".",
  "RecordBuffer": 10,
  "Index": true,
  "IndexBase": 1,
  "IndexName": "Rec"
}

 

Restrictions

 

Structure of JSon buffer must be a flat structure with only one level of key/value pairs.

JSon String, Numeric, Boolean and Null JSon elements are supported.

JSon Arrays or objects are NOT supported.

 

See also

 

Examples

 
Dim ExportCsvOpt as new cOptions

 
String JSonFileName     = App_SourcePath + "jsonConfigFile.json"
String JSonStringBuffer = "{ ""Index"": true, ""IndexBase"": 1, ""IndexName"": ""Rec""}"

 
ExportCsvOpt.FromJSon(File_Load(JSonFileName))

ExportCsvOpt.FromJSon(File JSonFileName)

ExportCsvOpt.FromJSon(JSonStringBuffer)