j2y.pp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. {
  2. This file is part of the Free Component Library
  3. Copyright (c) 2017 by Michael Van Canneyt [email protected]
  4. JSON To YAML syntax converter demo
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. program j2y;
  12. {$MODE OBJFPC}
  13. {$H+}
  14. uses fpjson,classes, jsonparser,json2yaml,sysutils;
  15. Var
  16. IFN,OFN : String;
  17. D : TJSONData;
  18. IFS,OFS : TStream;
  19. jtoy : TJSONToYaml;
  20. begin
  21. If ParamCount=0 then
  22. writeln('Usage j2y infile [outfile]');
  23. IFN:=ParamStr(1);
  24. OFN:=ParamStr(2);
  25. if OFN='' then
  26. OFN:=Changefileext(IFN,'yaml');
  27. D:=Nil;
  28. OFS:=Nil;
  29. jtoy:=Nil;
  30. IFS:=TFileStream.Create(IFN,fmOpenRead or fmShareDenyWrite);
  31. try
  32. D:=GetJSON(IFS);
  33. OFS:=TFileStream.Create(OFN,fmCreate);
  34. JTOY:=TJSONToYaml.Create;
  35. JTOY.Convert(D,OFS);
  36. finally
  37. D.Free;
  38. IFS.Free;
  39. OFS.Free;
  40. JTOY.Free;
  41. end;
  42. end.