File: jsonpack.lpr

package info (click to toggle)
doublecmd 1.1.30-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 43,968 kB
  • sloc: pascal: 374,335; sh: 1,180; ansic: 724; makefile: 132; python: 52; xml: 16
file content (58 lines) | stat: -rw-r--r-- 1,102 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
program jsonpack;

{$mode objfpc}{$H+}

uses
  {$IFDEF UNIX}
  cthreads,
  {$ENDIF}
  SysUtils,
  Classes,
  JsonParser,
  fpJson;

var
  AFileName: String;
  AConfig: TJSONData;
  AStream: TFileStream;
  AOptions: TFormatOptions;
begin
  if ParamStr(1) = '-c' then
  begin
    AOptions:= AsCompactJSON;
  end
  else if ParamStr(1) = '-d' then
  begin
    AOptions:= [foDoNotQuoteMembers]
  end
  else begin
    WriteLn;
    WriteLn(ExtractFileName(ParamStr(0)), ' <Options> <json-file>');
    WriteLn;
    WriteLn('Options:');
    WriteLn(' -c                  compress json-file');
    WriteLn(' -d                  decompress json-file');
    WriteLn;
    Exit;
  end;
  AFileName:= ParamStr(2);

  AStream:= TFileStream.Create(AFileName, fmOpenRead or fmShareDenyNone);
  try
    AConfig:= GetJSON(AStream, True);
  finally
    AStream.Free;
  end;
  try
    with TStringList.Create do
    try
      Text:= AConfig.FormatJSON(AOptions);
      SaveToFile(AFileName);
    finally
      Free;
    end;
  finally
    AConfig.Free;
  end;
end.