PHPackages                             alexkratky/variable-to-json - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. alexkratky/variable-to-json

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

alexkratky/variable-to-json
===========================

Convert any variable or object to json.

v1.0.0(6y ago)0511MITPHPPHP &gt;=7.0

Since Apr 13Pushed 5y ago1 watchersCompare

[ Source](https://github.com/AlexKratky/VariableToJson)[ Packagist](https://packagist.org/packages/alexkratky/variable-to-json)[ Docs](https://panx.eu/)[ RSS](/packages/alexkratky-variable-to-json/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependenciesVersions (5)Used By (1)

VariableToJson
==============

[](#variabletojson)

Convert any variable or object to json.

### Installation

[](#installation)

`composer require alexkratky/variable-to-json`

### Usage

[](#usage)

```
require 'vendor/autoload.php';

use AlexKratky\VariableToJson;

$x = new TestClass(); // test class
$x->load();
$x->load2();
$x->load3();

file_put_contents("output.json", VariableToJson::convert($x, true));

file_put_contents("output2.json", VariableToJson::convert([
    'test' => 1
], true));

file_put_contents("output3.json", VariableToJson::convert(function(string $text ="xx") {
    echo $text;
}, true));
```

### Custom options

[](#custom-options)

- `setDepth($maxDepth = 5)` - Set maximum depth of object's scan
- `setLength($maxLength = 300)` - Set maximum string length

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~15 days

Total

3

Last Release

2190d ago

Major Versions

v0.2.0 → v1.0.02020-05-14

### Community

Maintainers

![](https://www.gravatar.com/avatar/b26914cbd1aae790e4de261206944ef146af64f8f9fc8b4484c0697dfa333d05?d=identicon)[AlexKratky](/maintainers/AlexKratky)

---

Top Contributors

[![AlexKratky](https://avatars.githubusercontent.com/u/33813757?v=4)](https://github.com/AlexKratky "AlexKratky (6 commits)")

---

Tags

phpjsonconvertobjectvariable

### Embed Badge

![Health badge](/badges/alexkratky-variable-to-json/health.svg)

```
[![Health](https://phpackages.com/badges/alexkratky-variable-to-json/health.svg)](https://phpackages.com/packages/alexkratky-variable-to-json)
```

###  Alternatives

[adhocore/json-fixer

Fix/repair truncated JSON data

51543.2k2](/packages/adhocore-json-fixer)[sbsaga/toon

🧠 TOON for Laravel — a compact, human-readable, and token-efficient data format for AI prompts &amp; LLM contexts. Perfect for ChatGPT, Gemini, Claude, Mistral, and OpenAI integrations (JSON ⇄ TOON).

6115.6k](/packages/sbsaga-toon)[blancks/fast-jsonpatch-php

Class designed to efficiently handle JSON Patch operations in accordance with the RFC 6902 specification

396.4k](/packages/blancks-fast-jsonpatch-php)[josantonius/json

PHP simple library for managing Json files.

1621.6k10](/packages/josantonius-json)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
