Download the PHP package brick/json-mapper without Composer

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

Brick\JsonMapper

Maps JSON data to strongly typed PHP DTOs.

Build Status Coverage Status Latest Stable Version Total Downloads License

Introduction

This library provides an easy-to-use, secure, and powerful way to map JSON data to strongly typed PHP objects.

It reads parameter types & annotations defined on your class constructors to map JSON data to your DTOs, and can work with zero configuration.

Installation

This library is installable via Composer:

Requirements

This library requires PHP 8.1 or later.

Project status & release process

While this library is still under development, it is well tested and considered stable enough to use in production environments.

The current releases are numbered 0.x.y. When a non-breaking change is introduced (adding new methods, optimizing existing code, etc.), y is incremented.

When a breaking change is introduced, a new 0.x version cycle is always started.

It is therefore safe to lock your project to a given release cycle, such as 0.1.*.

If you need to upgrade to a newer release cycle, check the release history for a list of changes introduced by each further 0.x.0 version.

Usage

Basic usage

JsonMapper provides a single method, map(), which takes a JSON string and a class name, and returns an instance of the given class.

Nested objects

JsonMapper will read the parameter types and annotations to map nested objects:

Arrays

Arrays can be documented with @param annotations, that will be parsed and used to map the JSON data:

Union types

If a parameter is a declared as a union of possible types, JsonMapper will automatically attempt to map the JSON data to the correct type:

To achieve this, JsonMapper attempts to map a JSON object to every possible PHP class in the union. If no class matches, or if several classes match, an exception is thrown.

Complex unions

JsonMapper can parse, map, and verify any combination of possibly nested types:

This currently comes with two limitations:

Enums

JsonMapper can map JSON strings and integers to backed enums:

Non-backed enums, i.e. enums that do not have a string or int value, are not supported on purpose.

Strictness

The library has very strict defaults (some of which can be overridden by config), and will throw an exception if the JSON data does not exactly match the DTO's constructor signature, or if the DTO contains invalid or unsupported @param annotations.

The types of the parameters must match exactly, with the same semantics as PHP's strict_types.

JsonMapper guarantees that every constructor parameter, even softly-typed with @param, will be passed a value that is compatible with the declared type. The result is a DTO that can be 100% trusted by your static analysis tool.

Options

The JsonMapper constructor accepts the following options:


All versions of json-mapper with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
brick/reflection Version ~0.5.0
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 brick/json-mapper contains the following files

Loading the files please wait ....