v2026.5.3
All Bundles
Bundle Streaming JSON parser for processing large documents without loading the full tree into memory. Reads tokens sequentially via a cursor-based API. Compile with -lib json.

StreamParser

Event driven stream JSON parser

stream := FileReader->New(filename);
if(stream->IsOpen()) {
  parser := StreamParser->New(stream);

  found := false;
  do {
    if(parser->FindElement("Value", 4)) {
      parser->Next();
      if(parser->GetTypeValue()->Equals("{d4db6850-5385-11d0-89e9-00a0c90a90ac}")) {
        found := true;
      };
    };
  }
  while(<>found & parser->Next());

  parser->GetTypeValue()->PrintLine();
};

stream->Close();

Operations

AtLevel #

Checks the current parse level

method : public : AtLevel(level:Int) ~ Bool

Parameters

NameTypeDescription
levelIntparse level

Return

TypeDescription
Boolcurrent parse level

Example

stream := FileReader->New("data.json");
parser := Data.JSON.Stream.StreamParser->New(stream);
while(parser->Next()) {
  if(parser->AtLevel(1)) { # only process tokens at depth 1
    parser->GetTypeValue()->PrintLine();
  };
};
stream->Close();

FindElement #

Find element by name

method : public : FindElement(name:String) ~ Bool

Parameters

NameTypeDescription
nameStringelement by name

Return

TypeDescription
Booltrue if found, false otherwise

Example

stream := FileReader->New("config.json");
parser := Data.JSON.Stream.StreamParser->New(stream);
if(parser->FindElement("version")) { # seek to "version" label
  parser->Next();
  parser->GetTypeValue()->PrintLine(); # print the value
};
stream->Close();

FindElement #

Find element by name

method : public : FindElement(name:String, level:Int) ~ Bool

Parameters

NameTypeDescription
nameStringelement by name
levelIntelement level

Return

TypeDescription
Booltrue if found, false otherwise

Example

stream := FileReader->New("data.json");
parser := Data.JSON.Stream.StreamParser->New(stream);
# find "id" only at nesting depth 2
if(parser->FindElement("id", 2)) {
  parser->Next();
  parser->GetTypeValue()->PrintLine();
};
stream->Close();

FindElement #

Find element by type

method : public : FindElement(type:StreamParser->Type) ~ Bool

Parameters

NameTypeDescription
typeStreamParser->Typeelement by type

Return

TypeDescription
Booltrue if found, false otherwise

Example

stream := FileReader->New("data.json");
parser := Data.JSON.Stream.StreamParser->New(stream);
# advance to the first array token
if(parser->FindElement(Data.JSON.Stream.StreamParser->Type->ARRAY)) {
  parser->GetTypeValue()->PrintLine(); # prints "["
};
stream->Close();

FindElement #

Find element by type

method : public : FindElement(type:StreamParser->Type, level:Int) ~ Bool

Parameters

NameTypeDescription
typeStreamParser->Typeelement by type
levelIntelement level

Return

TypeDescription
Booltrue if found, false otherwise

Example

stream := FileReader->New("data.json");
parser := Data.JSON.Stream.StreamParser->New(stream);
# find a number token at depth 1
if(parser->FindElement(Data.JSON.Stream.StreamParser->Type->NUMBER, 1)) {
  parser->GetTypeValue()->PrintLine();
};
stream->Close();

GetLevel #

Get JSON parse level. Level increase as objects and arrays are parsed.

method : public : GetLevel() ~ Int

Return

TypeDescription
IntJSON parse level

Example

stream := FileReader->New("data.json");
parser := Data.JSON.Stream.StreamParser->New(stream);
while(parser->Next()) {
  level := parser->GetLevel(); # depth: 0=top, 1=first object, etc.
  "{$level}: {$parser->GetTypeValue()}"->PrintLine();
};
stream->Close();

GetType #

Get JSON type

method : public : GetType() ~ StreamParser->Type

Return

TypeDescription
StreamParser->TypeJSON type

Example

stream := FileReader->New("data.json");
parser := Data.JSON.Stream.StreamParser->New(stream);
while(parser->Next()) {
  type := parser->GetType(); # get enum type of current token
  parser->GetTypeName()->PrintLine();
};
stream->Close();

GetTypeName #

Get JSON type name

method : public : GetTypeName() ~ String

Return

TypeDescription
StringJSON type name

Example

stream := FileReader->New("data.json");
parser := Data.JSON.Stream.StreamParser->New(stream);
while(parser->Next()) {
  parser->GetTypeName()->PrintLine(); # e.g. "label", "string", "number"
};
stream->Close();

GetTypeValue #

Get JSON values

method : public : GetTypeValue() ~ String

Return

TypeDescription
StringJSON value if it exists, blank string otherwise

Example

stream := FileReader->New("data.json");
parser := Data.JSON.Stream.StreamParser->New(stream);
while(parser->Next()) {
  value := parser->GetTypeValue(); # get string form of token
  value->PrintLine();
};
stream->Close();

HasError #

Checks if a parsing error occurred

method : public : HasError() ~ Bool

Return

TypeDescription
Booltrue if error, false otherwise

Example

stream := FileReader->New("broken.json");
parser := Data.JSON.Stream.StreamParser->New(stream);
while(parser->Next()) { };
if(parser->HasError()) { # true if malformed JSON was encountered
  "Parse failed"->ErrorLine();
};
stream->Close();

New # constructor

Constructor

New(input:InputStream)

Parameters

NameTypeDescription
inputInputStreaminput stream

Example

stream := FileReader->New("data.json");
if(stream->IsOpen()) {
  parser := Data.JSON.Stream.StreamParser->New(stream);
  parser->Next();
  stream->Close();
};

Next #

Checks for the next JSON token

method : public : Next() ~ Bool

Return

TypeDescription
Booltrue if next token exists, false otherwise

Example

stream := FileReader->New("data.json");
parser := Data.JSON.Stream.StreamParser->New(stream);
while(parser->Next()) { # iterate all tokens
  parser->GetTypeName()->Print();
  " => "->Print();
  parser->GetTypeValue()->PrintLine();
};
stream->Close();