Skip to content

JSON serialization support would be nice #22

@judgej

Description

@judgej

Was trying to convert a Sequence object to JSON, and just getting {} as the result. However, serializing $sequence->all() works just fine - gives me an array of items. Obviously the items themselves need to be serializable too, but that's not php-collection's problem.

So, could Sequence (and I guess the other collection types) be given JSON serialisation support? It is probably just as simple as adding this method and implementing \JsonSerializable:

    public function jsonSerialize() {
        return $this->all();
    }

I can provide a PR if this is something you would like.

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