uses
  dfileiterator_nosysutils,
  derror,
  dstream,
  dstreammem,
  dstreamfile,
  dnode,
  djson_sax,
  djson_node,
  djson;

var
  C: AnsiChar;
  Stream: PStream;
  StreamMem: TStreamMem;
  StreamFile: TStreamFile;
  Json: TJson;
  Parser: TJsonParser;
  NodeManager: TNodeManagerStatic;
  Value: TNodeValue;
  FileIterator: TFileIterator;

function TestFile(const F: AnsiString; out Msg: AnsiString): Boolean;
var
  Error: TError;
  OutStream: TStreamFile;
begin
  OutStream.Init('', FM_WRITE);
  if ParseJsonValueToNode(F, @NodeManager, Value, True, @Error) then begin
    Msg := 'ok';
    Result := True;
  end else begin
    Msg := 'error: ' + Error.Msg;
    Result := False;
  end;
  OutStream.Done;
end;

procedure TestDir(const Dir: AnsiString);
var
  Msg: AnsiString;
  B: Boolean;
begin
  FileIterator.Init(Dir + '/*');
  while FileIterator.Next do begin
    if FileIterator.FileName[1] = '.' then
      continue;
    Write(FileIterator.FileName);
    B := TestFile(Dir + '/' + FileIterator.FileName, Msg);
    if (B and (FileIterator.FileName[1] = 'n')) or ((not B) and (FileIterator.FileName[1] = 'y')) then
      Write(' ! ');
    Writeln(': ', Msg);
  end;
  FileIterator.Done;
end;

begin
  NodeManager.Init;
  TestDir('inputs');
  NodeManager.Done;
end.
