Skip to content

v:format.json.encode converts "false" to "{}" on top level #1486

Closed
@maechler

Description

The current implementation of v:format.json.encode converts the value false to {}, when used on top level. Although the JSON spec allows any value (object, array, true, false, null, numbers) to be on top level. (https://stackoverflow.com/questions/17220924/does-the-top-level-value-in-json-have-to-be-an-array-or-object)

{v:format.json.encode(value: falseVariable)} --> returns {}
{v:format.json.encode(value: trueVariable)} --> returns true

The problem is the following code because empty(false) evaluates to true:

if (true === empty($value)) {
return '{}';
}

If you think this could safely be removed, I could prepare a pull request.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions