Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array of indeterminate "repeats"? #14

Closed
ghost opened this issue Apr 30, 2013 · 3 comments
Closed

Array of indeterminate "repeats"? #14

ghost opened this issue Apr 30, 2013 · 3 comments

Comments

@ghost
Copy link

ghost commented Apr 30, 2013

Hello -

I'm enjoying json_expressions very much so far, but have a simple question (I hope!).

I have the following json for the home page of a store which I need to validate. At present, I am not sure how to specify that I want an array to be allowed to "repeat" 1 or more times. There are presently 12 entries, but there could easily be more or less.

{
title: "Shop Outdoor Gear",
categories: [
{
id: "3707807",
href: "/categories/3707807",
title: "Men's Clothing"
},
{
id: "3677318",
href: "/categories/3677318",
title: "Women's Clothing"
},
{...

Also, my pattern, in a very basic (albeit non-working) form:

            pattern = {
                    title: String,
                    categories: [{
                                    id: Integer,
                                    href: String,
                                    title: String
                            }]
            }

Is there a way in which this can be accomplished? Thank you kindly in advance.

@chancancode
Copy link
Owner

Thanks for the feedback @matthew-bb! I think this is totally valid. I don't think there's an easy way to do this right now. If you just want match exactly N of these, it should be possible with:

categories: [
  {
    id: Integer,
    href: String,
    title: String
  }
] * 10

(if you use ignore_extra_values, you can kind of do "at least" N, but those extra stuff won't be matched to this template.)

I'll add this to my mental 2.0 features list. Hopefully I'll finally get to work on that soon

@sricc
Copy link

sricc commented Jul 24, 2013

+1. This would be a great feature. Thanks for a great gem!

@chancancode
Copy link
Owner

Closed in favour of #18

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants