Skip to content

problem relating to getAsJson #25

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;

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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