fungio/json-builder
A Laravel/PHP package for assembling JSON programmatically. It provides a fluent, chainable API to build nested arrays and objects cleanly, so you can generate structured JSON for APIs, configs, or dynamic payloads without hand-writing arrays. Keeps complex JSON construction readable and maintainabl...
Architecture fit. fungio/json-builder is a standalone, dependency-free PHP string builder that composes JSON incrementally while letting the caller choose, per node, between escaped values (via json_encode) and raw/pre-serialized JSON fragments. It is not a serializer, not PSR-7/PSR-17 aware, and has no Laravel service provider or facade — it is a leaf utility you wire in by hand. That makes it architecturally neutral: it can sit anywhere a string is produced (controllers, jobs, export services, API transformers), but it earns its place only where you legitimately need to splice already-serialized JSON into a larger payload without double-encoding.
Integration feasibility. Composer install is trivial; the API surface is small (startObject/endObject, startArray/endArray, addMember, addElement, getResult, plus a builder interface). The real feasibility question is PHP version support: the package targets PHP 5.6+ and mirrors the abandoned egeloen/ivory-json-builder, so its constraints and test matrix predate modern Laravel. Expect to verify compatibility against your PHP 8.x runtime and Laravel version before committing; if constraints block install, you are looking at a fork or a replace in composer.json.
Technical risk.
json_encode, so the risky surface is narrow.Key questions. Do we actually have raw JSON fragments to embed (e.g., pre-serialized sub-payloads, GraphQL envelope assembly, streaming exports), or would json_encode with JSON_UNESCAPED_* flags plus JsonSerializable suffice? If we need it, who owns the fork and the PHP 8 compatibility patch? What is the blast radius if the package is abandoned mid-cycle? Is there a rule preventing raw insertion of user data?
Stack fit. In a Laravel stack, JSON is normally handled by Eloquent resources, JsonResponse, and json_encode. This package is a poor default and a reasonable exception: use it only in the narrow seam where you must concatenate pre-encoded JSON (bulk export writers, webhook envelope builders, template-rendered fragments). Everywhere else, native encoding is the correct owner of the concern.
Migration path. There is no migration to this package worth planning at scale — the realistic path is the reverse: if you inherit ad-hoc '{' . '"key":' . $json . '}' string concatenation, this package is a clean, testable replacement for that pattern. If you are greenfield, treat it as a "no" until a concrete raw-JSON requirement appears. If a need does appear, wrap it behind an application-owned interface (JsonEnvelopeBuilder) so the vendor type never leaks into domain code and the dependency is swappable in one file.
Compatibility. Pin the version explicitly and add a composer.json gate on PHP. Because dependents are zero, do not assume upstream will fix a PHP 8.4 deprecation — assume you will. Check whether the fork's test suite runs on your CI matrix; if not, add a smoke test that exercises escaped and raw paths and asserts the result round-trips through json_decode.
Sequencing.
Maintenance. The dominant cost. Zero dependents and zero stars signals a package that will not receive fixes; budget for an internal fork or a replace shim, and assign an owner. The code is small enough that "we maintain it" is credible, but only if someone is named. Pair it with a CI job that fails on PHP upgrade deprecations.
Support. Effectively none from upstream. Support is your team plus reading ~a few hundred lines of source. That is acceptable for a leaf utility and unacceptable for anything on the critical path without a wrapper.
Scaling. Runtime cost is negligible — string concatenation and per-value json_encode, linear in output size. The scaling concern is memory for very large documents, not CPU, and that is identical whether you use this package or native encoding. No concurrency or state issues; builders should be treated as single-use.
Failure modes.
startObject/endObject produces invalid JSON silently. Assert round-trip in tests."{\"a\":1}". Mitigate with naming and code review, not docs alone.Ramp-up. Low — the API is intuitive for anyone who has built JSON by hand, and the interface is small enough to learn in under an hour. The real ramp-up cost is judgment: teaching the team when raw insertion is legitimate versus when it is a vulnerability. Budget a short internal note and a lint/review rule rather than training sessions. Net: cheap to adopt, cheap to run, expensive to own if it becomes load-bearing — deploy it as a wrapped, optional utility, not a platform dependency.
How can I help you explore Laravel packages today?