github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/website/content/docs/job-specification/hcl2/functions/encoding/jsondecode.mdx (about)

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