I need to load a JSON file, change a value and then write it back to disk.
This is easy using SuperObject, but how do I do the same thing using the System.JSON unit?
const
PathToX = 'AllCategories.Category[0].subCategory[0].products[0].views.view[0].x';
var
JsonFilename: string;
JO: ISuperObject; // from the SuperObject unit
JV: TJsonValue; // from the System.Json unit
begin
JsonFilename := ExtractFilePath(Application.ExeName)+'product.json');
// Using the SuperObject unit:
JO := SO(TFile.ReadAllText(JsonFilename));
WriteLn('The old value of "x" is ', JO[PathToX].AsString);
WriteLn('Changing value of x to "123"');
JO.S[PathToX] := '123'; // Set the value of "x"
WriteLn('The new value of "x" is ', JO[PathToX].AsString);
// Now trying to do the same thing using the System.Json unit:
JV := TJSONObject.ParseJsonValue(TFile.ReadAllText(JsonFilename));
WriteLn('The old value of "x" is ', JV.GetValue<string>(PathToX));
WriteLn('Changing value of x to "123"');
// Question: What code should go here to set the value of "x" using System.JSON ???
WriteLn('The new value of "x" is ', JV.GetValue<string>(PathToX));
There doesn't seem to be a "SetValue" equivalent to the "GetValue" method in System.JSON.