JSON

JSON parser.

It is Variant based and the parser must be freed.

var
  JsonParser: TJsonParser;
  Element: TJSONElement;
  I: Integer;
begin
  JsonParser := TJSONParser.Create();

  Element := JsonParser.AddObject('someObject');
  Element.AddValue('someInteger', 123);
  Element.AddValue('someString', 'HelloWorld');

  for I := 0 to Element.Count - 1 do
    WriteLn(Element.Item[I].ValueType);
end.

TJSONElement.Keys

property TJSONElement.Keys: TStringArray;

TJSONElement.Values

property TJSONElement.Values: TVariantArray;

TJSONElement.Count

property TJSONElement.Count: Integer;

TJSONElement.Item

property TJSONElement.Item[Index: Integer]: TJSONElement;

TJSONElement.ValueType

property TJSONElement.ValueType: EJSONValueType;

TJSONElement.Value

property TJSONElement.Value: Variant;
property TJSONElement.Value(NewValue: Variant);

TJSONElement.IsValue

property TJSONElement.IsValue: Boolean;

TJSONElement.IsArray

property TJSONElement.IsArray: Boolean;

TJSONElement.IsObject

property TJSONElement.IsObject: Boolean;

TJSONElement.AsString

property TJSONElement.AsString: String;

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.Clone

function TJSONElement.Clone: TJSONElement;

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;
function TJSONParser.AddArray(Key: String; Values: TVariantArray): TSimbaJSONElement;

TJSONParser.AddObject

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

TJSONParser.AddElement

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

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.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.


TJSONParser.Count

property TJSONParser.Count: Integer;

TJSONParser.Item

property TJSONParser.Item[Index: Integer]: TJSONElement;

TJSONParser.AsString

property TJSONParser.AsString: String;

TJSONParser.Values

property TJSONParser.Values: TVariantArray;

TJSONParser.Keys

function TJSONParser.Keys: TStringArray;