Skip to content

Instantly share code, notes, and snippets.

@kofno
Created June 24, 2017 18:24
Show Gist options
  • Select an option

  • Save kofno/b7b90148069504415299de947fd085b3 to your computer and use it in GitHub Desktop.

Select an option

Save kofno/b7b90148069504415299de947fd085b3 to your computer and use it in GitHub Desktop.
Array decoder
import { array, string } from 'jsonous';
const decoder = array(string());
decoder.decodeAny([ 'foo', 'bar' ]); // --> Ok(['foo', 'bar'])
decoder.decodeAny('foo'); // --> Err('Expected an array. Instead found foo')
decoder.decodeAny([ 'foo', 42, 'bar']); // --> Err('Error found in array at [1]: Expected a string. Instead found 42')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment