I have a code that changes a value of a determinated pair in a existent JSON file and works perfectly. Now i need add one object and one pair to this file, using great part this same code. So how do this?
Thank you.
uses
 System.Json, ShFolder, System.IOUtils;
...
function GetSpecialFolderPath(folder : integer) : string;
 const
   SHGFP_TYPE_CURRENT = 0;
 var
   path: array [0..MAX_PATH] of char;
 begin
   if SUCCEEDED(SHGetFolderPath(0,folder,0,SHGFP_TYPE_CURRENT,@path[0])) then
     Result := path
   else
     Result := '';
 end;
procedure ChangeChromeSetting(const ATarget, Avalue: string);
var
  specialfolder: integer;
  caminhochrome: String;
  JSONObj, Obj: TJSONObject;
  JSONPair: TJSONPair;
  OldValue: string;
begin
  specialFolder := CSIDL_LOCAL_APPDATA;
  caminhochrome := GetSpecialFolderPath(specialFolder);
  caminhochrome := caminhochrome + '\Google\Chrome\User Data\Local State';
 if fileexists(caminhochrome) then
  begin
    Obj := TJSONObject.Create;
    JSONObj := TJSONObject.ParseJSONValue(TFile.ReadAllText(caminhochrome)) as TJSONObject;
    if not Assigned(JSONObj) then raise Exception.Create('Cannot read file: ' + caminhochrome);
    try
      OldValue := JSONObj.GetValue<string>(ATarget);
      if not SameText(OldValue, Avalue) then
      begin
        JSONPair := JSONObj.Get(ATarget);
        JSONPair.JsonValue.Free;
        JSONPair.JsonValue := TJSONString.Create(Avalue);
        ///////////////////////////////////////////////////
        Obj.AddPair('enabled', TJSONBool.Create(false)); // Trying add pair
        JSONObj.AddPair('hardware_acceleration_mode', Obj);  // Trying add object
        //////////////////////////////////////////////////
        TFile.WriteAllText(caminhochrome, JSONObj.ToJSON); // Don't add object and pair
      end;
    finally
      JSONObj.Free;
    end;
  end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
  ChangeChromeSetting('hardware_acceleration_mode_previous', 'false');
end;
This is result that i'm waiting
"hardware_acceleration_mode":{"enabled":false}