Download the PHP package baldie81/json-marshaler without Composer

On this page you can find all versions of the php package baldie81/json-marshaler. 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-marshaler

JsonMarshaler

Attribute-based JSON marshalling/unmarshalling for PHP 8.2+ with built-in validation.

Inspired by C# records and Go's encoding/json marshaler. PHP doesn't have records, but since 8.2 we have readonly classes — and with constructor promoted properties (available since 8.0), we can emulate the same concise, immutable data structures that make marshalling feel natural.

Why use it?

Installation

Requires PHP 8.2 or higher.

Quick Start

Define a readonly class with promoted properties — the PHP equivalent of a record:

Marshal to JSON:

Unmarshal from JSON:

Custom JSON Keys

Use #[JsonProperty] to map a property to a different JSON key — just like Go's json:"field_name" struct tags or C#'s [JsonPropertyName]:

Omit Empty

Use omitEmpty: true on #[JsonProperty] to exclude properties from the JSON output when their value is null, an empty string, or an empty array — similar to Go's omitempty tag. Zero values like 0, 0.0, and false are not considered empty.

Sensitive Fields

Use sensitive: true on #[JsonProperty] to mask a property's value with **** during marshalling. The actual value is preserved in the object — only the JSON output is masked:

Nested Objects

Nested objects are resolved automatically via type hints — no extra configuration needed:

Typed Collections

Use #[JsonList] to unmarshal arrays of objects:

SelfHydrating Trait

Add fromJson() and toJson() directly to your class:

Validation

Validators are applied as attributes on properties and run automatically during unmarshalling. Stack multiple validators on a single property:

Invalid data throws an InvalidArgumentException:

Built-in Validators

Validator Description
#[NotEmpty] Rejects null, empty strings, and empty arrays
#[Email] Valid email address
#[Url] Valid URL
#[MinLength(n)] Minimum string length
#[MaxLength(n)] Maximum string length
#[Pattern('/regex/')] Matches a regular expression
#[Range(min, max)] Numeric value within a range
#[Positive] Positive number (int or float)
#[PositiveInteger] Positive integer
#[IsInteger] Must be an integer
#[InList('a', 'b', ...)] Value must be one of the listed strings

Custom Validators

Implement ValidatorInterface to create your own:

Then use it like any built-in validator:

Working with API Responses

JsonMarshaler is a natural fit for consuming JSON APIs. Instead of navigating nested associative arrays, unmarshal the response directly into typed objects:

The same approach works for outgoing responses — marshal your objects directly in a controller:

Full Example

Putting it all together — a record-like readonly class with nested objects, typed collections, validation, and self-hydration:

License

MIT


All versions of json-marshaler with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
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 baldie81/json-marshaler contains the following files

Loading the files please wait ...