JSON

JSON parser. It is Variant based.

TJSONElement.Keys

function TJSONElement.Keys: TStringArray;

TJSONElement.Count

function TJSONElement.Count: Integer;

TJSONElement.GetItem

function TJSONElement.GetItem(Index: Integer): TJSONElement;

TJSONElement.AddValue

procedure TJSONElement.AddValue(Key: String; Value: Variant);

TJSONElement.AddArray

function TJSONElement.AddArray(Key: String): TJSONElement;

TJSONElement.AddArray

function TJSONElement.AddArray(Key: String; Values: TVariantArray): TJSONElement;

TJSONElement.AddObject

function TJSONElement.AddObject(Key: String): TJSONElement;

TJSONElement.AddNull

function TJSONElement.AddNull(Key: String): TJSONElement;

TJSONElement.AddElement

procedure TJSONElement.AddElement(Key: String; Element: TJSONElement);

TJSONElement.ValueType

function TJSONElement.ValueType: EJSONValueType;

TJSONElement.GetValue

function TJSONElement.GetValue: Variant;

TJSONElement.SetValue

procedure TJSONElement.SetValue(NewValue: Variant);

TJSONElement.AsString

function TJSONElement.AsString: String;

TJSONElement.Clone

function TJSONElement.Clone: TJSONElement;

TJSONElement.IsValue

function TJSONElement.IsValue: Boolean;

TJSONElement.IsArray

function TJSONElement.IsArray: Boolean;

TJSONElement.IsObject

function TJSONElement.IsObject: Boolean;

TJSONElement.Delete

procedure TJSONElement.Delete(Key: String);

TJSONElement.Delete

procedure TJSONElement.Delete(Index: Integer);

TJSONElement.Clear

procedure TJSONElement.Clear;

TJSONElement.Find

function TJSONElement.Find(Key: String; out Element: TJSONElement): Boolean;

TJSONElement.HasKey

function TJSONElement.HasKey(Key: String): Boolean;

Returns True if the Key exists in the JSON object.

TJSONElement.HasKey

function TJSONElement.HasKey(Keys: TStringArray): Boolean;

Returns True if any of the Keys exists in the JSON object.

TJSONElement.HasKeys

function TJSONElement.HasKeys(Keys: TStringArray): Boolean;

Returns True if all Keys exists in the JSON object.

TJSONParser.Create

function TJSONParser.Create(Str: String = ''): TJSONParser; static;

Create a JSON Parser. Optional Str parameter which will parse the string into the parser.

  • This needs to be free’d when finished.

  • This is a static method. Example:

var MyJsonParser: TJSONParser;
begin
  MyJsonParser := TJSONParser.Create();
  MyJsonParser.AddValue('someString', 'HelloWorld');
  MyJsonParser.AddValue('someInt', 1234);
  WriteLn MyJsonParser.AsString();
  MyJsonParser.Free();
end;

TJSONParser.CreateFromFile

function TJSONParser.CreateFromFile(FileName: String): TJSONParser; static;

Create a JSON parser from a json file.

  • This needs to be free’d when finished.

  • This is a static method. Example:

var MyJsonParser: TJSONParser;
begin
  MyJsonParser := TJSONParser.CreateFromFile('somefile.json');
  WriteLn(MyJsonParser.Keys());
  MyJsonParser.Free();
end;

TJSONParser.SaveToFile

function TJSONParser.SaveToFile(FileName: String): Boolean;

TJSONParser.Clear

procedure TJSONParser.Clear;

TJSONParser.AddNull

function TJSONParser.AddNull(Key: String): TJSONElement;

TJSONParser.AddValue

procedure TJSONParser.AddValue(Key: String; Value: Variant);

TJSONParser.AddArray

function TJSONParser.AddArray(Key: String): TJSONElement;

TJSONParser.AddObject

function TJSONParser.AddObject(Key: String): TJSONElement;

TJSONParser.AddElement

procedure TJSONParser.AddElement(Key: String; Element: TJSONElement);

TJSONParser.Count

function TJSONParser.Count: Integer;

TJSONParser.GetItem

function TJSONParser.GetItem(Index: Integer): TJSONElement;

TJSONParser.AsString

function TJSONParser.AsString: String;

TJSONParser.Find

function TJSONParser.Find(Key: String; out Element: TJSONElement): Boolean;

TJSONParser.Delete

procedure TJSONParser.Delete(Key: String);

TJSONParser.Delete

procedure TJSONParser.Delete(Index: Integer);

TJSONParser.FindPath

function TJSONParser.FindPath(Path: String; out Element: TJSONElement): Boolean;

TJSONParser.Keys

function TJSONParser.Keys: TStringArray;

TJSONParser.HasKey

function TJSONParser.HasKey(Key: String): Boolean;

Returns True if the Key exists in the root JSON parser.

TJSONParser.HasKey

function TJSONParser.HasKey(Keys: TStringArray): Boolean;

Returns True if any of the Keys exists in the root JSON parser.

TJSONParser.HasKeys

function TJSONParser.HasKeys(Keys: TStringArray): Boolean;

Returns True if all Keys exists in the root JSON parser.