/claim https://github.com/zio/zio-blocks/issues/685
What Was Done:
Json.scala Created a JSON Abstract Data Type with 6 cases (Object, Array, String, Number, Boolean, Null) plus JsonError for error handling. Includes toDynamicValue/fromDynamicValue conversions to bridge with the existing schema system.
JsonPatch.scala Implemented the core patching engine:
diff(old, new) - Computes minimal operations to transform one JSON into another using LCS algorithms for strings/arrays apply(json, mode) - Applies operations with 3 modes: Strict (fail on error), Lenient (skip errors), Clobber (force changes) ++ - Composes patches sequentially (monoid) Operations - Set, NumberDelta, StringEdit, ArrayEdit, ObjectEdit cover all JSON mutation types Interop - toDynamicPatch/fromDynamicPatch for converting to/from the existing DynamicPatch type JsonPatchSpec.scala Property-based and unit tests verifying:
Algebraic laws (monoid identity/associativity, diff roundtrip) All operation types work correctly Mode behaviors differ appropriately Edge cases and error handling
How It Solves Issue #685 The issue requested a JSON-specific patching system that mirrors DynamicPatch but is optimized for JSON’s simpler model (4 leaf types vs 30 primitive values). This implementation provides exactly that—a complete, lawful, tested JsonPatch type that can diff, apply, and compose patches on JSON values with configurable failure handling.
John Oluwafemi
@John6150
ZIO
@ZIO
John Oluwafemi
@John6150