Download the PHP package webfiori/jsonx without Composer

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

WebFiori Json

A PHP library for creating and parsing JSON and JSONx strings. Supports all PHP scalar types, arrays, and objects with flexible property naming styles.

PHP 8.1+

Table of Contents

Key Features

Supported PHP Versions

Build Status

Installation

Quick Start

Output:

You can also build the object incrementally:

Usage

Working With Arrays

Output:

Working With Objects

Using JsonI Interface

Implement JsonI to fully control how an object is serialized:

Output:

Auto-Mapping Objects

Objects that don't implement JsonI are mapped automatically using:

  1. Public getter methods — any zero-parameter method prefixed with get is called. The property name is derived by stripping get (e.g. getName() → Name with style none, or name with style camel).
  2. Public properties — extracted via reflection and added as-is.

Use #[JsonIgnore] to exclude specific getters or properties, and #[JsonProperty] to override the output name:

Output:

Property Naming Styles

Four naming styles are supported: none (default), camel, snake, kebab.
Three letter cases are supported: same (default), upper, lower.

Set application-wide defaults:

Decoding JSON

Decode a JSON string:

Read from a file:

Typed Deserialization

Deserialize JSON directly into typed objects:

Nested objects are resolved automatically via constructor type hints. Use #[JsonType] for arrays of objects:

Runtime type mapping without attributes:

Saving to File

Converting to Array

The toArray() method converts a Json object to a plain PHP associative array without the overhead of encoding to a JSON string and decoding it back:

This is useful when passing structured data to functions expecting arrays, PHPUnit assertions, or merging with other arrays. See examples/11-to-array.php for more examples.

JSONx

JSONx is an IBM standard that represents JSON as XML:

Output:

Error Handling

All errors throw \WebFiori\Json\JsonException:

API Reference

Classes

Class Description
Json Main class for building, reading, and deserializing JSON data
JsonI Interface for custom object serialization
JsonConverter Handles serialization to JSON and JSONx strings
JsonDeserializer Handles typed deserialization of JSON into objects
Property Represents a single JSON property
CaseConverter Converts property names between naming styles
JsonTypes Constants for JSON data types
JsonException Exception thrown on JSON errors

Attributes

Attribute Target Description
#[JsonIgnore] Method, Property Exclude from serialization
#[JsonProperty(name)] Method, Property Override output name
#[JsonType(class, isArray)] Parameter, Property Specify type for deserialization

Key Methods — Json

Method Description
add(string $key, mixed $value, bool $arrayAsObj = false): bool Add any value
addString(string $key, string $val): bool Add a string
addNumber(string $key, int\|float $value): bool Add a number
addBoolean(string $key, bool $val = true): bool Add a boolean
addNull(string $key): bool Add a null value
addArray(string $key, array $value, bool $asObject = false): bool Add an array
addObject(string $key, object &$val): bool Add an object
get(string $key): mixed Get a property value
hasKey(string $key): bool Check if a key exists
remove(string $key): ?Property Remove a property
setPropsStyle(string $style, string $lettersCase = 'same'): void Change naming style
setIsFormatted(bool $bool): void Toggle formatted output
setTypeMap(array $map): void Set type map for typed deserialization via get()
toJSONString(): string Get JSON string
toJSONxString(): string Get JSONx string
toArray(): array Get plain PHP associative array
toJsonFile(string $fileName, string $path, bool $override = false): void Save to file
Json::decode(string $jsonStr): Json Decode a JSON string
Json::decodeAs(string $jsonStr, string $className): object Decode and hydrate a typed object
Json::fromJsonFile(string $path): Json Load from a JSON file
Json::setDefaults(?string $style, ?string $case, ?bool $formatted): void Set application-wide defaults
Json::resetDefaults(): void Reset to library defaults

Testing

Contributing

Contributions are welcome! Please open an issue or submit a pull request on GitHub.

License

This library is licensed under the MIT License. See the LICENSE file for more details.

Support

If you encounter any issues, please open an issue on GitHub.

Changelog

See CHANGELOG.md for a list of changes.


All versions of jsonx with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
ext-json Version *
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 webfiori/jsonx contains the following files

Loading the files please wait ...