Download the PHP package farzai/json-serializer without Composer

On this page you can find all versions of the php package farzai/json-serializer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package json-serializer

JSON Serializer for PHP

Latest Version on Packagist Tests Total Downloads

A high-performance, type-safe JSON serializer and deserializer for PHP 8.1+ with advanced features including attribute-based configuration, nested object support, versioning, transformers, and comprehensive error handling.

Installation

You can install the package via composer:

Features

When to Use This Library

✅ Use This Library When:

⚠️ Use Native Functions When:

Performance Trade-offs

Serialization: ~50-60x slower than native json_encode due to rich features

Deserialization: Competitive with native json_decode (~1.0x speed)

Memory: Only ~7% overhead compared to native functions

Usage

Basic Serialization

Basic Deserialization

Nested Objects & Collections

Attributes

Versioning

Custom Transformers

Union Types

Error Handling

Circular Reference Detection

The library automatically detects and prevents circular references during serialization:

Builder Pattern

Security & Configuration

Protect your application from malicious or malformed JSON with built-in security features:

Security Best Practices:

Type Coercion Modes

Control how the deserializer handles type mismatches with three coercion modes:

Coercion Rules

STRICT Mode:

SAFE Mode (Default):

LENIENT Mode:

Custom Type Handlers

Extend the serializer with custom type handlers for specialized serialization logic:

Use Cases for Custom Type Handlers:

PSR-16 Cache Support

Improve performance by caching metadata with any PSR-16 compatible cache:

Compatible Cache Libraries:

Performance Impact:

Streaming & Large Files

For processing large JSON files without loading everything into memory, use the streaming API:

Streaming Deserialization

Lazy Iterator

Process large JSON arrays with on-demand deserialization:

Path-based Extraction

Extract specific data without parsing the entire JSON:

Memory-Efficient Processing

Generator Serialization

Serialize large datasets memory-efficiently using PHP generators:

Benefits of Generator Serialization:

When to Use Generators:

Performance

The library has been benchmarked against native json_encode/decode functions using PHPBench. Benchmarks run on PHP 8.1+ with comparable results across versions.

Note: This library prioritizes features and type safety over raw speed. The performance overhead is justified by capabilities like attribute-based configuration, versioning, transformers, and streaming support. For simple use cases where these features aren't needed, native json_encode/decode functions are recommended.

Serialization Performance

Data Size Native JsonSerializer Ratio Notes
Small (<1KB) 1.0μs 49.3μs ~49x slower Overhead negligible for small data
1MB 325μs 20.3ms ~62x slower Rich feature set trade-off
5MB 1.7ms 101.7ms ~60x slower Consistent overhead ratio
10MB 3.6ms 204.6ms ~57x slower Scales linearly

Deserialization Performance

Data Size Native JsonSerializer Ratio Notes
1MB 942μs 936μs Competitive Same speed as native!
5MB 4.9ms 4.8ms Competitive Same speed as native!
10MB 9.9ms 10.0ms Competitive Same speed as native!

Object Hydration Performance

Operation Time Notes
Decode to Class (1MB) 1.1ms Minimal overhead for object mapping
Decode to Class (5MB) 5.5ms Scales linearly with data size
Nested Objects 36μs Fast recursive hydration

Memory Usage

Operation Memory Peak Notes
Native (10MB) 32.5MB Baseline
JsonSerializer (10MB) 34.9MB ~7% overhead
Streaming (10MB) 34.9MB Constant memory with file operations

Key Findings

Deserialization: JsonSerializer achieves native-level performance for deserialization, making it ideal for API consumption and data processing.

Serialization: While slower than native for encoding, the overhead is justified by the rich feature set:

Memory Efficiency: Memory usage is comparable to native functions with only ~7% overhead for medium to large datasets.

Running Benchmarks

Troubleshooting

Common Issues and Solutions

Memory Limit Errors

Type Mismatch Errors

Circular Reference Errors

Performance Issues

Max Depth Exceeded

Performance Optimization Tips

  1. Use PSR-16 Cache: Cache metadata for classes you serialize frequently
  2. Stream Large Files: Use iterateFile() for files > 100MB
  3. Disable Unused Features: Turn off circular reference detection if not needed
  4. Use Native for Simple Data: Reserve this library for complex object mapping
  5. Batch Processing: Process multiple objects in batches with streaming

Getting Help

Testing

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.


All versions of json-serializer with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package farzai/json-serializer contains the following files

Loading the files please wait ...