Skip to content

[Serializer] [JsonStreamer] Add streaming JSON documentation #20486

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 7.3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions serializer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,38 @@ all the properties of the class::
// ...
}

Serializing JSON using streams
------------------------------

Symfony is able of encoding PHP data structures to JSON streams and decoding
JSON streams back into PHP data structures.

To do so, it relies on the JsonStreamer component, which is designed for high
efficiency and can process large JSON data incrementally without needing to
load the entire content into memory.

When deciding between the :doc:`Serializer component <serializer>` and the
JsonStreamer component, consider the following:

- **Serializer Component**: Ideal for scenarios requiring flexibility, such as
dynamically manipulating object shapes using normalizers and denormalizers,
or handling complex objects which multiple serialization representation.
Plus, it allows working with formats beyond JSON (and even with a custom
format of yours).

- **JsonStreamer Component**: Ideal for simple objects and tasks that
demand high performance and minimal memory usage. It's particularly
effective when processing very large JSON datasets or in scenarios that
require streaming JSON in real-time without loading the entire dataset
into memory.

Choosing between the two depends on your specific use case requirements.
The JsonStreamer component is tailored to optimize for performance and memory
efficiency, while the Serializer component offers flexibility and broader
format support.

Read more about streaming JSON in :doc:`/serializer/streaming_json`.

Serializing to or from PHP Arrays
---------------------------------

Expand Down
Loading