Check if data already exists in json file with liquid

Hello
I created a form to collect user data
Then I used an Api to get the user data
And so far I have been successful ( I displayed the data on my site using jekyll-json-get plugin)

Where the problem is users could be able to register with multiple emails…

The file looks like this
{
name: me
email: me@gmail.com
}
{
name: me1
email: me@gmail.com
}
What I want to do is…
On form submission if the email entered as been used by anyone else stop form submission and ask for another email

You could use Liquid’s map and uniq filters to get a list of emails to block:

{% assign blocklist = site.data.registrations | map: "email" | uniq %} 
# Result: ["me@gmail.com", "bob@gmail.com", ...]

Thank you.
This should definitely solve my problem

As helpful as this is
I still can’t get it to work correctly…
In my config file I have

  - data: seeds
    json: 'http://json file in here/'

My json file

{created" => "date",
 "data" => "{
 "first name" => "me",
 "email" => "me@me.com"
},
"folder" => "null"
}

{ "created" => "date",
data" => "{
 "first name" => "me",
 "email" => "me@me.com"
},
"folder" => "null"
}

… And so on

Then I did

{% assign email = site.data.seeds | map: "email" | uniq %}

{{ email }}

I don’t know if I did that right (am kinda new to Jekyll and the liquid world)

A useful filter for debugging is inspect, which will print out data. For example, you could use it to check the JSON data, and test map-filtering to extract the data and email fields:

{{ site.data.seeds | inspect }}

{{ site.data.seeds | map: "data" | map: "email" | inspect }}
1 Like