Skip to content

Asychronous type validation / coercion #53

Description

@Pampattitude

Hi,

I am currently using jjv for parsing user-provided JSON from a web form. However, one of the fields I can get is a foreign key to a resource, and I need to valide it then coerce it into a complete JSON object (the entry in a database related to said foreign key).

Is there a way for me to include this check and coercion in jjv?

If jjv does not allow this, is it a planned feature? One way to do it would be to check and apply asynchronous logic if 1 < Function.length, both for validation and coercion.

As an example, my use case is this:
I have a user-provided JSON in this form:

{
  "idToForeign": 1234,
  "credentials": {
    "username": "robert",
    "password": "pwd"
  }
}

What I need to validate is that idToForeign is an integer, has a related entry in the database that I will fetch a second later and has permission to reference it. Permission may not be validable with jjv, as jjv does not (and, in my understanding, does not mean to) allow validation of fields in relation with each other, but I still would like to check and fetch said entry during the jjv validation / coercion, before processing this input.


Thanks a bunch in advance!

Regards,

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions