DocsPlaygroundBlogCommunityPackages
  • Playground
  • Blog
  • Community
  • Packages
  • X
  • Bluesky
  • GitHub
  • Forum
Language ManualAPISyntax LookupReact
Overview
Stdlib
submodules
  • Array
  • ArrayBuffer
  • AsyncIterator
  • BigInt
  • BigInt64Array
    • Constants
    BigUint64Array
    • Constants
  • Bool
  • Console
  • DataView
  • Date
    • UTC
  • Dict
  • Error
    • URIError
    • TypeError
    • SyntaxError
    • ReferenceError
    • RangeError
    • EvalError
  • Exn
  • Float
    • Constants
    Float32Array
    • Constants
    Float64Array
    • Constants
    Int
    • Ref
    • Bitwise
    • Constants
    Int16Array
    • Constants
    Int32Array
    • Constants
    Int8Array
    • Constants
  • IntervalId
  • Intl
    • Segments
    • Segmenter
    • RelativeTimeFormat
    • PluralRules
    • NumberFormat
      • Grouping
    • Locale
    • ListFormat
    • DateTimeFormat
    • Collator
    • Common
  • Iterator
  • JSON
    • Decode
    • Encode
      • v
        bool
      • v
        null
      • v
        string
      • v
        int
      • v
        float
      • v
        object
      • v
        array
      • v
        stringArray
      • v
        floatArray
      • v
        intArray
      • v
        boolArray
      • v
        objectArray
    • Classify
    JsError
    • URIError
    • TypeError
    • SyntaxError
    • ReferenceError
    • RangeError
    • EvalError
  • JsExn
  • Lazy
  • List
  • Map
  • Math
    • Int
    • Constants
  • Null
  • Nullable
  • Object
  • Option
  • Ordering
  • Pair
  • Promise
  • RegExp
    • Result
  • Result
  • Set
  • String
  • Symbol
  • TimeoutId
  • Type
    • Classify
  • TypedArray
  • Uint16Array
    • Constants
    Uint32Array
    • Constants
    Uint8Array
    • Constants
    Uint8ClampedArray
    • Constants
  • WeakMap
  • WeakSet
  • Docs / API / Stdlib / Json / Encode

    Encode

    bool

    RESCRIPT
    let bool: bool => t

    Returns a boolean as JSON.

    Examples

    RESCRIPT
    JSON.Encode.bool(true)

    null

    RESCRIPT
    let null: t

    Returns null as a JSON value.

    Examples

    RESCRIPT
    JSON.Encode.null

    string

    RESCRIPT
    let string: string => t

    Returns a string as JSON.

    Examples

    RESCRIPT
    JSON.Encode.string("hello world")

    int

    RESCRIPT
    let int: int => t

    Returns an int as JSON.

    Examples

    RESCRIPT
    JSON.Encode.int(42)

    float

    RESCRIPT
    let float: float => t

    Returns a float as JSON.

    Examples

    RESCRIPT
    JSON.Encode.float(42.0)

    object

    RESCRIPT
    let object: dict<t> => t

    Returns a dict as a JSON object.

    Examples

    RESCRIPT
    let dict = Dict.fromArray([ ("foo", JSON.Encode.string("bar")), ("hello", JSON.Encode.string("world")), ]) JSON.Encode.object(dict)

    array

    RESCRIPT
    let array: array<t> => t

    Returns an array as JSON.

    Examples

    RESCRIPT
    let array = [JSON.Encode.string("hello world"), JSON.Encode.int(42)] JSON.Encode.array(array)

    stringArray

    RESCRIPT
    let stringArray: array<string> => t

    Returns an array of strings as a JSON object.

    floatArray

    RESCRIPT
    let floatArray: array<float> => t

    Returns an array of floats as a JSON object.

    intArray

    RESCRIPT
    let intArray: array<int> => t

    Returns an array of integers as a JSON object.

    boolArray

    RESCRIPT
    let boolArray: array<bool> => t

    Returns an array of booleans as a JSON object.

    objectArray

    RESCRIPT
    let objectArray: array<dict<t>> => t

    Returns an array of objects as a JSON object.

    Types and values
    • v
      bool
    • v
      null
    • v
      string
    • v
      int
    • v
      float
    • v
      object
    • v
      array
    • v
      stringArray
    • v
      floatArray
    • v
      intArray
    • v
      boolArray
    • v
      objectArray

    © 2025 The ReScript Project

    About
    • Community
    • ReScript Association
    Find us on