@zio.dev/zio-blocks 0.0.1 → 0.0.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.md +143 -15
- package/package.json +5 -2
- package/reference/binding.md +8 -14
- package/reference/chunk.md +36 -36
- package/reference/docs.md +2 -2
- package/reference/dynamic-value.md +34 -34
- package/reference/formats.md +16 -16
- package/reference/json-schema.md +20 -20
- package/reference/json.md +47 -47
- package/reference/optics.md +51 -37
- package/reference/reflect.md +3 -3
- package/reference/registers.md +7 -7
- package/reference/schema.md +18 -18
- package/reference/syntax.md +16 -16
- package/scope.md +481 -161
- package/reference/modifier.md +0 -276
- package/reference/reflect-transform.md +0 -387
- package/reference/type-class-derivation-internals.md +0 -632
package/reference/json.md
CHANGED
|
@@ -29,7 +29,7 @@ Key design decisions:
|
|
|
29
29
|
|
|
30
30
|
### Using Constructors
|
|
31
31
|
|
|
32
|
-
```scala
|
|
32
|
+
```scala
|
|
33
33
|
import zio.blocks.schema.json.Json
|
|
34
34
|
|
|
35
35
|
// Object with named fields
|
|
@@ -51,7 +51,7 @@ val nothing = Json.Null
|
|
|
51
51
|
|
|
52
52
|
### Parsing JSON Strings
|
|
53
53
|
|
|
54
|
-
```scala
|
|
54
|
+
```scala
|
|
55
55
|
import zio.blocks.schema.json.Json
|
|
56
56
|
import zio.blocks.schema.SchemaError
|
|
57
57
|
|
|
@@ -66,7 +66,7 @@ val json = Json.parseUnsafe("""{"items": [1, 2, 3]}""")
|
|
|
66
66
|
|
|
67
67
|
ZIO Blocks provides compile-time validated string interpolators for JSON:
|
|
68
68
|
|
|
69
|
-
```scala
|
|
69
|
+
```scala
|
|
70
70
|
import zio.blocks.schema._
|
|
71
71
|
import zio.blocks.schema.json._
|
|
72
72
|
|
|
@@ -91,7 +91,7 @@ The `json"..."` interpolator validates JSON syntax at compile time, catching err
|
|
|
91
91
|
The `Json` type provides unified methods for type testing and narrowing with path-dependent return types.
|
|
92
92
|
`JsonType` also implements `Json => Boolean`, so it can be used directly as a predicate for filtering.
|
|
93
93
|
|
|
94
|
-
```scala
|
|
94
|
+
```scala
|
|
95
95
|
import zio.blocks.schema.json.{Json, JsonType}
|
|
96
96
|
|
|
97
97
|
val json: Json = Json.parseUnsafe("""{"count": 42}""")
|
|
@@ -117,7 +117,7 @@ val strings = json.select.query(JsonType.String) // all string values in the JS
|
|
|
117
117
|
|
|
118
118
|
### Direct Value Access
|
|
119
119
|
|
|
120
|
-
```scala
|
|
120
|
+
```scala
|
|
121
121
|
import zio.blocks.schema.json.Json
|
|
122
122
|
|
|
123
123
|
val obj = Json.Object("a" -> Json.Number(1))
|
|
@@ -133,7 +133,7 @@ arr.elements // Chunk(Json.Number(1), Json.Number(2))
|
|
|
133
133
|
|
|
134
134
|
Navigate into objects by key and arrays by index:
|
|
135
135
|
|
|
136
|
-
```scala
|
|
136
|
+
```scala
|
|
137
137
|
import zio.blocks.schema.json.Json
|
|
138
138
|
import zio.blocks.schema.SchemaError
|
|
139
139
|
|
|
@@ -161,7 +161,7 @@ val name: Either[SchemaError, String] = firstName.as[String] // Right("Alice")
|
|
|
161
161
|
|
|
162
162
|
Use `DynamicOptic` paths for complex navigation:
|
|
163
163
|
|
|
164
|
-
```scala
|
|
164
|
+
```scala
|
|
165
165
|
import zio.blocks.schema._
|
|
166
166
|
import zio.blocks.schema.json._
|
|
167
167
|
|
|
@@ -186,7 +186,7 @@ val sameName = json.get("company").get("employees")(0).get("name").as[String]
|
|
|
186
186
|
|
|
187
187
|
`JsonSelection` is a fluent wrapper for navigation results, enabling composable chaining:
|
|
188
188
|
|
|
189
|
-
```scala
|
|
189
|
+
```scala
|
|
190
190
|
import zio.blocks.schema.json.{Json, JsonSelection}
|
|
191
191
|
|
|
192
192
|
val json = Json.parseUnsafe("""{"users": [{"name": "Alice"}]}""")
|
|
@@ -208,7 +208,7 @@ result.isFailure // false
|
|
|
208
208
|
|
|
209
209
|
### Terminal Operations
|
|
210
210
|
|
|
211
|
-
```scala
|
|
211
|
+
```scala
|
|
212
212
|
import zio.blocks.schema.json.{Json, JsonSelection}
|
|
213
213
|
import zio.blocks.schema.SchemaError
|
|
214
214
|
|
|
@@ -222,8 +222,8 @@ val anyValue: Either[SchemaError, Json] = selection.any
|
|
|
222
222
|
val allValues: Either[SchemaError, Json] = selection.all
|
|
223
223
|
|
|
224
224
|
// Get underlying result
|
|
225
|
-
val underlying:
|
|
226
|
-
val
|
|
225
|
+
val underlying: Option[zio.blocks.chunk.Chunk[Json]] = selection.values
|
|
226
|
+
val asChunk: zio.blocks.chunk.Chunk[Json] = selection.toChunk // empty on error
|
|
227
227
|
|
|
228
228
|
// Decode to specific types
|
|
229
229
|
val asString: Either[SchemaError, String] = selection.as[String]
|
|
@@ -238,7 +238,7 @@ val asDouble: Either[SchemaError, Double] = selection.as[Double]
|
|
|
238
238
|
|
|
239
239
|
### Setting Values
|
|
240
240
|
|
|
241
|
-
```scala
|
|
241
|
+
```scala
|
|
242
242
|
import zio.blocks.schema._
|
|
243
243
|
import zio.blocks.schema.json._
|
|
244
244
|
|
|
@@ -255,7 +255,7 @@ val result = json.setOrFail(p".user.email", Json.String("alice@example.com"))
|
|
|
255
255
|
|
|
256
256
|
### Modifying Values
|
|
257
257
|
|
|
258
|
-
```scala
|
|
258
|
+
```scala
|
|
259
259
|
import zio.blocks.schema._
|
|
260
260
|
import zio.blocks.schema.json._
|
|
261
261
|
|
|
@@ -277,7 +277,7 @@ val result = json.modifyOrFail(p".count") {
|
|
|
277
277
|
|
|
278
278
|
### Deleting Values
|
|
279
279
|
|
|
280
|
-
```scala
|
|
280
|
+
```scala
|
|
281
281
|
import zio.blocks.schema._
|
|
282
282
|
import zio.blocks.schema.json._
|
|
283
283
|
|
|
@@ -294,7 +294,7 @@ val result = json.deleteOrFail(p".missing")
|
|
|
294
294
|
|
|
295
295
|
### Inserting Values
|
|
296
296
|
|
|
297
|
-
```scala
|
|
297
|
+
```scala
|
|
298
298
|
import zio.blocks.schema._
|
|
299
299
|
import zio.blocks.schema.json._
|
|
300
300
|
|
|
@@ -311,7 +311,7 @@ val withNew = json.insert(p".newField", Json.String("value"))
|
|
|
311
311
|
|
|
312
312
|
Transform children before parents:
|
|
313
313
|
|
|
314
|
-
```scala
|
|
314
|
+
```scala
|
|
315
315
|
import zio.blocks.schema.json.Json
|
|
316
316
|
import zio.blocks.schema.DynamicOptic
|
|
317
317
|
|
|
@@ -331,7 +331,7 @@ val doubled = json.transformUp { (path, value) =>
|
|
|
331
331
|
|
|
332
332
|
Transform parents before children:
|
|
333
333
|
|
|
334
|
-
```scala
|
|
334
|
+
```scala
|
|
335
335
|
import zio.blocks.schema.json.Json
|
|
336
336
|
import zio.blocks.schema.DynamicOptic
|
|
337
337
|
|
|
@@ -351,7 +351,7 @@ val withId = json.transformDown { (path, value) =>
|
|
|
351
351
|
|
|
352
352
|
Rename object keys throughout the structure:
|
|
353
353
|
|
|
354
|
-
```scala
|
|
354
|
+
```scala
|
|
355
355
|
import zio.blocks.schema.json.Json
|
|
356
356
|
|
|
357
357
|
val json = Json.parseUnsafe("""{"user_name": "Alice", "user_age": 30}""")
|
|
@@ -372,7 +372,7 @@ val camelCase = json.transformKeys { (path, key) =>
|
|
|
372
372
|
|
|
373
373
|
Keep only values matching a predicate using `retain`, or remove values using `prune`:
|
|
374
374
|
|
|
375
|
-
```scala
|
|
375
|
+
```scala
|
|
376
376
|
import zio.blocks.schema.json.{Json, JsonType}
|
|
377
377
|
|
|
378
378
|
val json = Json.parseUnsafe("""{"a": 1, "b": null, "c": 2, "d": null}""")
|
|
@@ -390,7 +390,7 @@ val onlyNumbers = json.retain(_.is(JsonType.Number))
|
|
|
390
390
|
|
|
391
391
|
Extract only specific paths:
|
|
392
392
|
|
|
393
|
-
```scala
|
|
393
|
+
```scala
|
|
394
394
|
import zio.blocks.schema._
|
|
395
395
|
import zio.blocks.schema.json._
|
|
396
396
|
|
|
@@ -408,7 +408,7 @@ val projected = json.project(p".user.name", p".user.email")
|
|
|
408
408
|
|
|
409
409
|
Split based on a predicate:
|
|
410
410
|
|
|
411
|
-
```scala
|
|
411
|
+
```scala
|
|
412
412
|
import zio.blocks.schema.json.{Json, JsonType}
|
|
413
413
|
|
|
414
414
|
val json = Json.parseUnsafe("""{"a": 1, "b": "text", "c": 2}""")
|
|
@@ -425,7 +425,7 @@ val (numbers, nonNumbers) = json.partition(_.is(JsonType.Number))
|
|
|
425
425
|
|
|
426
426
|
Accumulate values from children to parents:
|
|
427
427
|
|
|
428
|
-
```scala
|
|
428
|
+
```scala
|
|
429
429
|
import zio.blocks.schema.json.Json
|
|
430
430
|
|
|
431
431
|
val json = Json.parseUnsafe("""{"values": [1, 2, 3, 4, 5]}""")
|
|
@@ -433,7 +433,7 @@ val json = Json.parseUnsafe("""{"values": [1, 2, 3, 4, 5]}""")
|
|
|
433
433
|
// Sum all numbers
|
|
434
434
|
val sum = json.foldUp(BigDecimal(0)) { (path, value, acc) =>
|
|
435
435
|
value match {
|
|
436
|
-
case n: Json.Number => acc + n.
|
|
436
|
+
case n: Json.Number => acc + n.value
|
|
437
437
|
case _ => acc
|
|
438
438
|
}
|
|
439
439
|
}
|
|
@@ -444,7 +444,7 @@ val sum = json.foldUp(BigDecimal(0)) { (path, value, acc) =>
|
|
|
444
444
|
|
|
445
445
|
Accumulate values from parents to children:
|
|
446
446
|
|
|
447
|
-
```scala
|
|
447
|
+
```scala
|
|
448
448
|
import zio.blocks.schema.json.Json
|
|
449
449
|
import zio.blocks.schema.DynamicOptic
|
|
450
450
|
|
|
@@ -460,7 +460,7 @@ val paths = json.foldDown(Vector.empty[DynamicOptic]) { (path, value, acc) =>
|
|
|
460
460
|
|
|
461
461
|
Combine two JSON values using different strategies:
|
|
462
462
|
|
|
463
|
-
```scala
|
|
463
|
+
```scala
|
|
464
464
|
import zio.blocks.schema.json.{Json, MergeStrategy}
|
|
465
465
|
|
|
466
466
|
val base = Json.parseUnsafe("""{"a": 1, "b": {"x": 10}}""")
|
|
@@ -502,7 +502,7 @@ val custom = base.merge(overlay, MergeStrategy.Custom { (path, left, right) =>
|
|
|
502
502
|
|
|
503
503
|
Clean up JSON values:
|
|
504
504
|
|
|
505
|
-
```scala
|
|
505
|
+
```scala
|
|
506
506
|
import zio.blocks.schema.json.Json
|
|
507
507
|
|
|
508
508
|
val json = Json.parseUnsafe("""{
|
|
@@ -535,7 +535,7 @@ val normalized = json.normalize
|
|
|
535
535
|
|
|
536
536
|
ZIO Blocks provides `JsonEncoder` and `JsonDecoder` type classes for converting between Scala types and `Json`:
|
|
537
537
|
|
|
538
|
-
```scala
|
|
538
|
+
```scala
|
|
539
539
|
import zio.blocks.schema.json.{Json, JsonEncoder, JsonDecoder}
|
|
540
540
|
|
|
541
541
|
// Encode Scala values to Json
|
|
@@ -549,7 +549,7 @@ val strResult = JsonDecoder[String].decode(Json.String("hello")) // Right("hell
|
|
|
549
549
|
|
|
550
550
|
### Built-in Encoders/Decoders
|
|
551
551
|
|
|
552
|
-
```scala
|
|
552
|
+
```scala
|
|
553
553
|
import zio.blocks.schema.json.{JsonEncoder, JsonDecoder}
|
|
554
554
|
|
|
555
555
|
// Primitives
|
|
@@ -577,7 +577,7 @@ JsonEncoder[java.util.UUID]
|
|
|
577
577
|
|
|
578
578
|
For complex types, use Schema-based derivation:
|
|
579
579
|
|
|
580
|
-
```scala
|
|
580
|
+
```scala
|
|
581
581
|
import zio.blocks.schema.Schema
|
|
582
582
|
import zio.blocks.schema.json.{Json, JsonEncoder, JsonDecoder}
|
|
583
583
|
|
|
@@ -600,7 +600,7 @@ val decoded = JsonDecoder[Person].decode(json)
|
|
|
600
600
|
|
|
601
601
|
When a `Schema` is in scope, you can use convenient extension methods directly on values:
|
|
602
602
|
|
|
603
|
-
```scala
|
|
603
|
+
```scala
|
|
604
604
|
import zio.blocks.schema._
|
|
605
605
|
|
|
606
606
|
case class Person(name: String, age: Int)
|
|
@@ -630,7 +630,7 @@ These extension methods provide a more ergonomic API compared to explicitly crea
|
|
|
630
630
|
|
|
631
631
|
### Using the `as` Method
|
|
632
632
|
|
|
633
|
-
```scala
|
|
633
|
+
```scala
|
|
634
634
|
import zio.blocks.schema.json.Json
|
|
635
635
|
import zio.blocks.schema.json.JsonDecoder
|
|
636
636
|
import zio.blocks.schema.{Schema, SchemaError}
|
|
@@ -654,7 +654,7 @@ val personUnsafe: Person = json.asUnsafe[Person]
|
|
|
654
654
|
|
|
655
655
|
### Basic Printing
|
|
656
656
|
|
|
657
|
-
```scala
|
|
657
|
+
```scala
|
|
658
658
|
import zio.blocks.schema.json.Json
|
|
659
659
|
|
|
660
660
|
val json = Json.Object("name" -> Json.String("Alice"), "age" -> Json.Number(30))
|
|
@@ -666,7 +666,7 @@ val compact: String = json.print
|
|
|
666
666
|
|
|
667
667
|
### With Writer Config
|
|
668
668
|
|
|
669
|
-
```scala
|
|
669
|
+
```scala
|
|
670
670
|
import zio.blocks.schema.json.Json
|
|
671
671
|
import zio.blocks.schema.json.WriterConfig
|
|
672
672
|
|
|
@@ -692,7 +692,7 @@ val indented4 = json.print(WriterConfig.withIndentionStep(4))
|
|
|
692
692
|
| `escapeUnicode` | `false` | Escape non-ASCII characters as `\uXXXX` |
|
|
693
693
|
| `preferredBufSize` | `32768` | Internal buffer size in bytes |
|
|
694
694
|
|
|
695
|
-
```scala
|
|
695
|
+
```scala
|
|
696
696
|
import zio.blocks.schema.json.WriterConfig
|
|
697
697
|
|
|
698
698
|
// Compact output (default)
|
|
@@ -723,7 +723,7 @@ val custom = WriterConfig
|
|
|
723
723
|
| `maxCharBufSize` | `4194304` | Maximum char buffer size (4MB) |
|
|
724
724
|
| `checkForEndOfInput` | `true` | Error on trailing non-whitespace |
|
|
725
725
|
|
|
726
|
-
```scala
|
|
726
|
+
```scala
|
|
727
727
|
import zio.blocks.schema.json.ReaderConfig
|
|
728
728
|
|
|
729
729
|
// Default configuration
|
|
@@ -740,7 +740,7 @@ val largeDoc = ReaderConfig
|
|
|
740
740
|
|
|
741
741
|
### To Bytes
|
|
742
742
|
|
|
743
|
-
```scala
|
|
743
|
+
```scala
|
|
744
744
|
import zio.blocks.schema.json.Json
|
|
745
745
|
|
|
746
746
|
val json = Json.Object("x" -> Json.Number(1))
|
|
@@ -755,7 +755,7 @@ val bytes: Array[Byte] = json.printBytes
|
|
|
755
755
|
|
|
756
756
|
Find all values matching a condition:
|
|
757
757
|
|
|
758
|
-
```scala
|
|
758
|
+
```scala
|
|
759
759
|
import zio.blocks.schema.json.Json
|
|
760
760
|
|
|
761
761
|
val json = Json.parseUnsafe("""{
|
|
@@ -776,7 +776,7 @@ val activeUsers = json.select.queryBoth { (path, value) =>
|
|
|
776
776
|
|
|
777
777
|
Flatten to path-value pairs:
|
|
778
778
|
|
|
779
|
-
```scala
|
|
779
|
+
```scala
|
|
780
780
|
import zio.blocks.schema.json.Json
|
|
781
781
|
import zio.blocks.schema.DynamicOptic
|
|
782
782
|
import zio.blocks.chunk.Chunk
|
|
@@ -796,7 +796,7 @@ val pairs: Chunk[(DynamicOptic, Json)] = json.toKV
|
|
|
796
796
|
|
|
797
797
|
Objects are compared **order-independently** (keys are compared as sorted sets):
|
|
798
798
|
|
|
799
|
-
```scala
|
|
799
|
+
```scala
|
|
800
800
|
import zio.blocks.schema.json.Json
|
|
801
801
|
|
|
802
802
|
val obj1 = Json.parseUnsafe("""{"a": 1, "b": 2}""")
|
|
@@ -809,7 +809,7 @@ obj1 == obj2 // true (order-independent)
|
|
|
809
809
|
|
|
810
810
|
JSON values have a total ordering for sorting:
|
|
811
811
|
|
|
812
|
-
```scala
|
|
812
|
+
```scala
|
|
813
813
|
import zio.blocks.schema.json.Json
|
|
814
814
|
|
|
815
815
|
val values = List(
|
|
@@ -830,7 +830,7 @@ Type ordering: Null < Boolean < Number < String < Array < Object
|
|
|
830
830
|
|
|
831
831
|
`JsonDiffer` computes the difference between two JSON values, producing a `JsonPatch` that transforms the source into the target:
|
|
832
832
|
|
|
833
|
-
```scala
|
|
833
|
+
```scala
|
|
834
834
|
import zio.blocks.schema.json.{Json, JsonPatch}
|
|
835
835
|
|
|
836
836
|
val source = Json.parseUnsafe("""{"name": "Alice", "age": 30}""")
|
|
@@ -856,7 +856,7 @@ The differ uses optimal operations:
|
|
|
856
856
|
|
|
857
857
|
### Computing and Applying Patches
|
|
858
858
|
|
|
859
|
-
```scala
|
|
859
|
+
```scala
|
|
860
860
|
import zio.blocks.schema.json.{Json, JsonPatch}
|
|
861
861
|
import zio.blocks.schema.patch.PatchMode
|
|
862
862
|
import zio.blocks.schema.SchemaError
|
|
@@ -887,7 +887,7 @@ val result3 = patch(original, PatchMode.Clobber)
|
|
|
887
887
|
|
|
888
888
|
### Composing Patches
|
|
889
889
|
|
|
890
|
-
```scala
|
|
890
|
+
```scala
|
|
891
891
|
import zio.blocks.schema.json.{Json, JsonPatch}
|
|
892
892
|
|
|
893
893
|
val patch1 = JsonPatch.diff(
|
|
@@ -912,7 +912,7 @@ val result = combined(Json.parseUnsafe("""{"x": 1}"""))
|
|
|
912
912
|
|
|
913
913
|
`JsonPatch` can be converted to and from `DynamicPatch` for interoperability with the typed patching system:
|
|
914
914
|
|
|
915
|
-
```scala
|
|
915
|
+
```scala
|
|
916
916
|
import zio.blocks.schema.json.JsonPatch
|
|
917
917
|
import zio.blocks.schema.patch.DynamicPatch
|
|
918
918
|
import zio.blocks.schema.SchemaError
|
|
@@ -930,7 +930,7 @@ val restored: Either[SchemaError, JsonPatch] = JsonPatch.fromDynamicPatch(dynami
|
|
|
930
930
|
|
|
931
931
|
Convert JSON to ZIO Blocks' semi-structured `DynamicValue`:
|
|
932
932
|
|
|
933
|
-
```scala
|
|
933
|
+
```scala
|
|
934
934
|
import zio.blocks.schema.json.Json
|
|
935
935
|
import zio.blocks.schema.DynamicValue
|
|
936
936
|
|
|
@@ -947,7 +947,7 @@ This enables interoperability with other ZIO Blocks formats (Avro, TOON, etc.).
|
|
|
947
947
|
|
|
948
948
|
Errors include path information for debugging:
|
|
949
949
|
|
|
950
|
-
```scala
|
|
950
|
+
```scala
|
|
951
951
|
import zio.blocks.schema.json.Json
|
|
952
952
|
import zio.blocks.schema.SchemaError
|
|
953
953
|
|
|
@@ -959,7 +959,7 @@ val result = json.get("users")(5).get("name").as[String]
|
|
|
959
959
|
|
|
960
960
|
### Error Properties
|
|
961
961
|
|
|
962
|
-
```scala
|
|
962
|
+
```scala
|
|
963
963
|
import zio.blocks.schema.SchemaError
|
|
964
964
|
import zio.blocks.schema.DynamicOptic
|
|
965
965
|
|