Download the PHP package s-mcdonald/phpjson without Composer

On this page you can find all versions of the php package s-mcdonald/phpjson. 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 phpjson

PHPJson

Source License PHP Compatibility

Master Build Status Develop Build Status

Coverage Status

A Fast and Lightweight PHP JSON Object Serialization Library.

💖 Support This Project

PHPJson is supported by your donations! Click the Sponsor link to display funding options.


PHPJson is a library that provides tools to work with JSON files and structures for PHP. Its primary feature is the ability to quickly and easily serialize PHP objects into JSON and deserialize (hydrate) JSON back to PHP objects.

Other features include

Project Objectives

  1. Simplify working with JSON structures.
  2. Enable fast and minimal-configuration serialization using attributes.
  3. Provide advanced serialization capabilities through traits and custom normalizers.
  4. Reduce duplication in business logic by streamlining common tasks.

Contents

Usage

Serialization

Quick usage

The fastest way to serialize a class into JSON is by using the JsonProperty attribute.

Or you can use the Json facade

Override Json Properties

You can customize property names in the JSON output by specifying your own names. This also applies when hydrating objects from JSON.

Serialize from methods

You can serialize values from getter methods, regardless of whether the method is public, protected, or private. PHPJson will automatically extract the value.

Nested Structures

PHPJson allows you to work seamlessly with complex, nested objects. Nested classes and their properties are serialized into valid JSON structures, matching the relationships between objects.

Serialization Using a trait

The above method utilizes the JsonProperty to serialize any object. This is by far the easiest and fasted way to convert your objects into Json. However, this will have some limitations. To overcome this, we have included two Facets called SerializesWithMapping and SerializesToJson. With these Facets you can customize the Serialization and export vastly more complex objects.

Serializing Enums

PHPJson supports the serialization of both pure and backed enums.

Pure Enum

Backed Enum

Casting Values

When serializing a PHP object to JSON, you might need to cast specific property values into different types for the JSON output. You can achieve this by using the JsonProperty attribute to specify the desired type using a JsonType, such as StringType or IntegerType.

Available types are;

Deserialize aka Object Hydration

Basic Hydration

With PHPJson, basic object hydration is straightforward. If your class properties match the structure and property names in your JSON, no additional attributes or mappings are required. The library will automatically map the JSON data to your class or entity.

Now deserialize the json string with the PHP class.

Hydration with Setter Methods

If your class relies on setters for processing or assigning values, PHPJson can hydrate using setter methods, provided these conditions are met:

Notice how the JsonProperty is used twice here, for hydration setter methods will be the preferred hydration point, since, setUserName can not be used for serialization, the property $userName will be used for this.

JsonBuilder

Fluently create Json objects using PHP.

JsonBuilder Basics

JsonBuilder Objects and Arrays

Json Formatting

Prettify & Uglify

Prettify or Uglify(minify) your json values

and then the reverse

Json Validate

PHP 8.3 onwards has the json_validate function. This library duplicates this behaviour so it can bve used in PHP 8.2

Reference

Installation

Install this package via composer, or simply fork/clone the repo.

Dependencies

PHP Versions

License

Json is licensed under the terms of the MIT License (See LICENSE file for details).

Contribute

🙌 Want to contribute?

Check out the issues section to get started.

Sponsor


All versions of phpjson 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 s-mcdonald/phpjson contains the following files

Loading the files please wait ....