TPLWorkflowJSON

Native Pascal, workflow preparation

Description

TPLWorkflowJSON (unit PDFlibWorkflowJSON.pas) is the node type of the native workflow JSON model. A node carries a TPLWorkflowJSONKind in Kind and its scalar content in Text: decoded text for wjString, the original spelling for wjNumber, and true or false for wjBoolean; wjNull ignores Text.

Children are owned: Add, SetMember and Insert transfer a child into the parent, Detach hands one back and the remove methods free it. Build requests with these members or obtain them from PLParseWorkflowJSON and PLParseWorkflowJSONEx, transform them with PLApplyWorkflowJSONPatch and PLMergeWorkflowJSON, and send them with Serialize; WorkflowDataTools walks through the whole call sequence.

Syntax

Delphi

TPLWorkflowJSON = Class
  Public
    Kind: TPLWorkflowJSONKind;
    Text: WideString;
    Constructor Create(AKind: TPLWorkflowJSONKind);
    Destructor Destroy; Override;
    Procedure Add(Const Name: WideString; Value: TPLWorkflowJSON);
    Function Count: Integer;
    Function Item(Index: Integer): TPLWorkflowJSON;
    Function Name(Index: Integer): WideString;
    Function Find(Const MemberName: WideString): TPLWorkflowJSON;
    Function StringValue(Const MemberName, DefaultValue: WideString): WideString;
    Function IntegerValue(Const MemberName: WideString; DefaultValue: Integer): Integer;
    Function BooleanValue(Const MemberName: WideString; DefaultValue: Boolean): Boolean;
    Function Serialize: WideString;
    Function Clone: TPLWorkflowJSON;
    Function EqualsValue(Other: TPLWorkflowJSON): Boolean;
    Function Pointer(Const Path: WideString): TPLWorkflowJSON;
    Procedure SetMember(Const MemberName: WideString; Value: TPLWorkflowJSON);
    Procedure Insert(Index: Integer; Value: TPLWorkflowJSON);
    Function Detach(Index: Integer): TPLWorkflowJSON;
    Function RemoveMember(Const MemberName: WideString): Boolean;
    Function Remove(Index: Integer): Boolean;
    Function TryInt64(Out Value: Int64): Boolean;
    Function TryDouble(Out Value: Double): Boolean;
    Function SerializeFormatted(Indent: Integer; SortNames: Boolean): WideString;
  End;

Fields

KindJSON type of this node; selects how Text and the children are interpreted
TextScalar content: decoded text for strings, the exact number spelling for numbers, true or false for booleans; ignored for wjNull and containers
Create / DestroyCreates a node of a given kind; the destructor frees every owned child, so free only the root
AddAppends a child to an array or object; an object member name must be unique and the parent takes ownership
SetMember / InsertReplaces or appends an object member by name, or inserts an array child at a zero-based index; the previous child is freed on replacement
Count / Item / Name / FindChild access; Item returns Nil and Name an empty string for an out-of-range index, and Find returns Nil outside an object or for a missing name
StringValue / IntegerValue / BooleanValueTyped member reads that return the supplied default when the member is absent or has a different kind
Serialize / SerializeFormattedCompact output, and indented output with optional UTF-16 name sorting and validation of stored number and boolean spellings
Clone / EqualsValueIndependent deep copy, and structural comparison that ignores object member order and compares numbers by value
PointerResolves a JSON Pointer path, with ~0 for a tilde and ~1 for a slash; an empty path selects this node
Detach / RemoveMember / RemoveTransfers a child to the caller, or frees it; an invalid index returns Nil or False and changes nothing
TryInt64 / TryDoubleStrict numeric conversion of a number node, returning False and zero for a non-conforming spelling

Remarks

Nil children, a child that already has an owner, a duplicate object member name passed to Add and an ownership cycle raise an exception before ownership changes.

Clone, EqualsValue, formatted serialization, patches and merges share a work budget of 256 nesting levels, 250,000 nodes and 32 Mi UTF-16 characters; exceeding it raises an exception.

Number comparison treats 1, 1.0 and 10e-1 as the same value, while Serialize still emits the stored spelling; use SerializeFormatted when stored numbers and booleans must be validated.

String serialization escapes quotes, backslashes and control characters, and replaces an unpaired UTF-16 surrogate with U+FFFD.

See also

WorkflowDataTools, ProbeWorkflowRequest, Add, SetMember, Serialize, SerializeFormatted, Clone, EqualsValue, Pointer, TryInt64