Load a JSON string into a data structure.
Also, create a new data structure and serialize it into JSON.

Use objects and arrays (as appropriate for your language)
and make sure your JSON is valid (https://jsonformatter.org).

 
program JsonTest;
 
{$APPTYPE CONSOLE}
 
{$R *.res}
 
uses
  System.SysUtils,
  Json;
 
type
  TJsonObjectHelper = class helper for TJsonObject
  public
    class function Deserialize(data: string): TJsonObject; static;
    function Serialize: string;
  end;
 
{ TJsonObjectHelper }
 
class function TJsonObjectHelper.Deserialize(data: string): TJsonObject;
begin
  Result := TJSONObject.ParseJSONValue(data) as TJsonObject;
end;
 
function TJsonObjectHelper.Serialize: string;
begin
  Result := ToJson;
end;
 
var
  people, deserialized: TJsonObject;
  bar: TJsonArray;
  _json: string;
 
begin
  people := TJsonObject.Create();
  people.AddPair(TJsonPair.Create('1', 'John'));
  people.AddPair(TJsonPair.Create('2', 'Susan'));
 
  _json := people.Serialize;
  Writeln(_json);
 
  deserialized := TJSONObject.Deserialize(_json);
  Writeln(deserialized.Values['2'].Value);
 
  deserialized := TJSONObject.Deserialize('{"foo":1 , "bar":[10,"apples"]}');
 
  bar := deserialized.Values['bar'] as TJSONArray;
  Writeln(bar.Items[1].Value);
 
  deserialized.Free;
  people.Free;
 
  Readln;
end.
 