A
A
Anton Medvedev2013-05-10 13:14:44
JavaScript
Anton Medvedev, 2013-05-10 13:14:44

Checking the JSON structure coming from the client to Node.JS

There was a task of checking the incoming JSON from the client on node.js. I have implemented a simple function:

json = 
  key: 'value'
  sub:
    key: 'value'
  extra: 'value'
check = expect json, {key: yes, sub: {key: yes}}
console.log check # true

Function code on Gist .

How do you do these checks?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Y
Yuri Shikanov, 2013-05-10
@Elfet

To solve your problem, there is already a ready-made json-gate module .
Used it - works great. Provides many useful features like optional values, list of allowed values ​​and other validators.

A
Artur Zayats, 2014-10-21
@zag2art

And I use https://github.com/zaggino/z-schema

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question