github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/website/content/docs/job-specification/hcl2/functions/encoding/jsondecode.mdx (about)

     1  ---
     2  layout: docs
     3  page_title: jsondecode - Functions - Configuration Language
     4  sidebar_title: jsondecode
     5  description: |-
     6    The jsondecode function decodes a JSON string into a representation of its
     7    value.
     8  ---
     9  
    10  # `jsondecode` Function
    11  
    12  `jsondecode` interprets a given string as JSON, returning a representation
    13  of the result of decoding that string.
    14  
    15  The JSON encoding is defined in [RFC 7159](https://tools.ietf.org/html/rfc7159).
    16  
    17  This function maps JSON values to
    18  [Nomad language values](/docs/job-specification/hcl2/expressions#types-and-values)
    19  in the following way:
    20  
    21  | JSON type | Nomad type                                                   |
    22  | --------- | ------------------------------------------------------------ |
    23  | String    | `string`                                                     |
    24  | Number    | `number`                                                     |
    25  | Boolean   | `bool`                                                       |
    26  | Object    | `object(...)` with attribute types determined per this table |
    27  | Array     | `tuple(...)` with element types determined per this table    |
    28  | Null      | The Nomad language `null` value                              |
    29  
    30  The Nomad language automatic type conversion rules mean that you don't
    31  usually need to worry about exactly what type is produced for a given value,
    32  and can just use the result in an intuitive way.
    33  
    34  ## Examples
    35  
    36  ```shell-session
    37  > jsondecode("{\"hello\": \"world\"}")
    38  {
    39    "hello" = "world"
    40  }
    41  > jsondecode("true")
    42  true
    43  ```
    44  
    45  ## Related Functions
    46  
    47  - [`jsonencode`](/docs/job-specification/hcl2/functions/encoding/jsonencode) performs the opposite operation, _encoding_
    48    a value as JSON.