ZI

/claim #679

Summary

Complete implementation of the Json data type for Issue #679. Introduces first-class JSON representation to zio-blocks with type-safe manipulation and deep Schema integration.


What This Adds

Core Json ADT

  • Six standard types: Object, Array, String, Number, Boolean, Null
  • Exhaustive pattern matching support
  • Number stores values as strings to preserve full precision
  • Convenience constructors for all Scala numeric types

Navigation and Selection

  • JsonSelection for fluent traversal with error accumulation
  • Path expressions via DynamicOptic, array indices, or object keys
  • Terminal operations: one, first, toArray

Modification Operations

Method Description
set / setOrFail Replace value at path
delete / deleteOrFail Remove value at path
insert / insertOrFail Insert into arrays
modify / modifyOrFail Transform value at path

Transformation and Folding

  • transformUp / transformDown for bottom-up and top-down traversal
  • transformKeys for bulk field renaming
  • foldUp / foldDown with OrFail variants
  • filter / filterNot on path-value pairs

Merging

Five built-in strategies:

  • Auto / Deep - Recursive object merge with array concatenation
  • Shallow - Top-level replacement only
  • Concat - Array-focused combination
  • Replace - Simple overwrite
  • Custom - User-defined merge function

Normalization and Diffing

  • normalize - Sort keys, standardize numbers
  • sortKeys - Recursive key ordering
  • dropNulls / dropEmpty - Remove null values and empty containers
  • diff - Produce RFC 6902 JsonPatch between two values

Patching

  • patch / patchUnsafe - Apply JsonPatch operations
  • Supports: add, remove, replace, move, copy, test
  • Batch wrapper for composing multiple operations

Validation

  • check / conforms for basic JsonSchema validation
  • Covers primitives, arrays, objects with required fields, optionals, unions

Encoding and Decoding

Input formats: String, CharSequence, Array[Byte], Chunk, ByteBuffer, Reader Output formats: String, Array[Byte], Chunk, ByteBuffer, Writer Typed conversion: as[A] / asUnsafe[A] via JsonDecoder

Type Class Integration

  • JsonEncoder[A] and JsonDecoder[A] type classes
  • Explicit JsonBinaryCodec takes priority over schema derivation

String Interpolators

  • p"path.to[0].field" - Path construction
  • j"""{"key": "value"}""" - JSON literal parsing
  • Implemented for both Scala 2 (blackbox macros) and Scala 3 (inline/quotes)

DynamicValue Interop

  • toDynamicValue / fromDynamicValue with full round-trip fidelity
  • toKV / fromKV for flat path-value representation
  • Temporal values serialize to ISO format strings

Testing

  • 1306 tests pass on JVM
  • Compiles on JVM, JS, Native
  • Compiles on Scala 2.13 and Scala 3.3
  • Passes scalafmt validation

Scope Notes

JsonPatch and JsonSchema are working but minimal placeholders, consistent with the issue marking them out-of-scope. Patch functionality supports diff/patch round-trips. Schema validation covers common cases but is not a full JSON Schema implementation.

Demo Video

https://github.com/user-attachments/assets/5b1f59f3-dd41-4854-884c-a2c3939ddac3

Claim

Total prize pool $4,000
Total paid $0
Status Pending
Submitted January 20, 2026
Last updated January 20, 2026

Contributors

NA

Nati

@natinew77-creator

100%

Sponsors

ZI

ZIO

@ZIO

$2,000
JA

Jacques Anidjar

@jacanidjar

$2,000