Skip to content

problem relating to getAsJson #25

@kjteng

Description

@kjteng

node.AsJson returns {"Name1":"v1","Name2":"v2"} when it is a root node but return "Name1":"v1","Name2":"v2" (invalid json) if the node is a sub-node.

This is due to the behaviour of FormatCompact (called in the GetAsJson) method. As a temporry workaround, I have modified getAsJson as follows. Kindly advise. TQ.

function TJsonNode.GetAsJson: string;
begin
if FKind in [nkObject, nkArray] then
begin
Result := FormatCompact;
// added:-
// if (FParent <> nil) and (FKind=nkObject) then
if (FKind=nkObject) and (not result.StartsWith('{')) then
result := '{' + result + '}'
end
else
Result := FValue;
end;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions