# Does dry-validation support schemas where the top level is an Array?

**URL:** <https://discourse.dry-rb.org/t/does-dry-validation-support-schemas-where-the-top-level-is-an-array/1557>\
**Category:** dry-validation\
**Created:** [November 16, 2022, 9:52am UTC](https://discourse.dry-rb.org/t/does-dry-validation-support-schemas-where-the-top-level-is-an-array/1557 "2022-11-16T09:52:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rickenharp](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/rickenharp/32/12_2.png) [@rickenharp](https://discourse.dry-rb.org/u/rickenharp)\
**Post date:** [November 16, 2022, 9:52am UTC](https://discourse.dry-rb.org/t/does-dry-validation-support-schemas-where-the-top-level-is-an-array/1557/1 "2022-11-16T09:52:15Z")

</div>

I’ve been trying to integrate dry-validation into a legacy app to have better validation of incoming data.

Some of the data is has this JSON layout:

```json
[
  {
    "affects_url": "http://localhost/" ,
    "confidence": 95
  },
  {
    "affects_url": "http://localhost/favicon.ico" ,
    "confidence": 95
  }
]

```

And my attempts of writing a contract for this so far have failed.

I thought, that this should work, but it returns an empty result:

```ruby
class MyContract < Dry::Validation::Contract
  json do
    array do
      required(:affects_url).filled(:string)
      required(:confidence).filled(:integer)
    end
  end
end

```

---

<div class="post-metadata">

**Author:** ![flash-gordon](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/flash-gordon/32/494_2.png) [@flash-gordon](https://discourse.dry-rb.org/u/flash-gordon)\
**Post date:** [November 16, 2022, 2:16pm UTC](https://discourse.dry-rb.org/t/does-dry-validation-support-schemas-where-the-top-level-is-an-array/1557/2 "2022-11-16T14:16:58Z")

</div>

It’s a feature request in dry-schema [Provide a way of defining schemas for arrays as root nodes · Issue #22 · dry-rb/dry-schema · GitHub](https://github.com/dry-rb/dry-schema/issues/22) I wrap such data with a key `Schema.(data: json)`

---

<div class="post-metadata">

**Author:** ![rickenharp](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/rickenharp/32/12_2.png) [@rickenharp](https://discourse.dry-rb.org/u/rickenharp)\
**Post date:** [November 17, 2022, 8:20am UTC](https://discourse.dry-rb.org/t/does-dry-validation-support-schemas-where-the-top-level-is-an-array/1557/3 "2022-11-17T08:20:47Z")

</div>

Oh, that’s a great workaround, thanks for the tip!
