This is the latest docs version
Quick Links
  • -Overview
  • -Language Features
  • -JS Interop
  • -Build System
Documentation
Language Manual
Reference for all language features
ReScript & React
First class bindings for ReactJS
GenType
Seamless TypeScript integration
Reanalyze
Dead Code & Termination analysis
Exploration
Packages
Explore third party libraries and bindings
Syntax Lookup
Discover all syntax constructs
APIPlaygroundBlogCommunity
  • Playground
  • Blog
  • Twitter
  • GitHub
  • Forum
Core Module
Overview
Core
submodules
  • Array
  • ArrayBuffer
  • AsyncIterator
  • BigInt
  • BigInt64Array
    • Constants
    BigUint64Array
    • Constants
  • Console
  • DataView
  • Date
    • UTC
  • Dict
  • Error
    • URIError
    • TypeError
    • SyntaxError
    • ReferenceError
    • RangeError
    • EvalError
  • Exn
  • Float
    • Constants
    Float32Array
    • Constants
    Float64Array
    • Constants
    Int
    • Constants
    Int16Array
    • Constants
    Int32Array
    • Constants
    Int8Array
    • Constants
  • Internal
  • Intl
    • Segments
    • Segmenter
    • RelativeTimeFormat
    • PluralRules
    • NumberFormat
      • Grouping
    • Locale
    • ListFormat
    • DateTimeFormat
    • Collator
    • Common
  • Iterator
  • JSON
    • Decode
      • v
        bool
      • v
        null
      • v
        string
      • v
        float
      • v
        object
      • v
        array
    • Encode
    • Classify
  • List
  • Map
  • MapperRt
  • Math
    • Int
    • Constants
  • Null
  • Nullable
  • Object
  • Option
  • Ordering
  • Promise
  • Re
    • Result
    RegExp
    • Result
  • Result
  • Set
  • String
  • Symbol
  • Type
    • Classify
  • TypedArray
  • Uint16Array
    • Constants
    Uint32Array
    • Constants
    Uint8Array
    • Constants
    Uint8ClampedArray
    • Constants
  • WeakMap
  • WeakSet
  • API / Core / Json / Decode

    Decode

    bool

    RESCRIPT
    let bool: t => option<bool>

    Decodes a single JSON value. If the value is a bool, it will return Some(bool) - otherwise it will return None.

    Examples

    RESCRIPT
    JSON.parseExn(`true`)->JSON.Decode.bool // Some(true) JSON.parseExn(`"hello world"`)->JSON.Decode.bool // None

    null

    RESCRIPT
    let null: t => option<Core__Null.t<'a>>

    Decodes a single JSON value. If the value is null, it will return Some(Null.t) - otherwise it will return None.

    Examples

    RESCRIPT
    JSON.parseExn(`null`)->JSON.Decode.null // Some(null) JSON.parseExn(`"hello world"`)->JSON.Decode.null // None

    string

    RESCRIPT
    let string: t => option<string>

    Decodes a single JSON value. If the value is a string, it will return Some(string) - otherwise it will return None.

    Examples

    RESCRIPT
    JSON.parseExn(`"hello world"`)->JSON.Decode.string // Some("hello world") JSON.parseExn(`42`)->JSON.Decode.string // None

    float

    RESCRIPT
    let float: t => option<float>

    Decodes a single JSON value. If the value is a float, it will return Some(float) - otherwise it will return None.

    Examples

    RESCRIPT
    JSON.parseExn(`42.0`)->JSON.Decode.float // Some(42.0) JSON.parseExn(`"hello world"`)->JSON.Decode.float // None

    object

    RESCRIPT
    let object: t => option<Core__Dict.t<t>>

    Decodes a single JSON value. If the value is an object, it will return Some(Dict.t) - otherwise it will return None.

    Examples

    RESCRIPT
    JSON.parseExn(`{"foo":"bar"}`)->JSON.Decode.object // Some({ foo: 'bar' }) JSON.parseExn(`"hello world"`)->JSON.Decode.object // None

    array

    RESCRIPT
    let array: t => option<array<t>>

    Decodes a single JSON value. If the value is an array, it will return Some(array) - otherwise it will return None.

    Examples

    RESCRIPT
    JSON.parseExn(`["foo", "bar"]`)->JSON.Decode.array // Some([ 'foo', 'bar' ]) JSON.parseExn(`"hello world"`)->JSON.Decode.array // None
    Types and values
    • v
      bool
    • v
      null
    • v
      string
    • v
      float
    • v
      object
    • v
      array

    © 2024 The ReScript Project

    Software and assets distribution powered by KeyCDN.

    About
    • Community
    • ReScript Association
    Find us on