Skip to content

Commit

Permalink
Add support for convert from json to object/list
Browse files Browse the repository at this point in the history
Signed-off-by: Hasan Turken <turkenh@gmail.com>
  • Loading branch information
turkenh committed Aug 29, 2023
1 parent 151ab38 commit 961431d
Showing 1 changed file with 51 additions and 1 deletion.
52 changes: 51 additions & 1 deletion content/master/concepts/patch-and-transform.md
Original file line number Diff line number Diff line change
Expand Up @@ -1098,6 +1098,8 @@ Supported `toType` values:
| `int` | A 32-bit integer value. |
| `int64` | A 64-bit integer value. |
| `string` | A string value. |
| `object` | An object. |
| `array` | An array. |
{{< /table >}}

#### Converting strings to booleans
Expand Down Expand Up @@ -1146,6 +1148,55 @@ suffix support.
format: quantity
```

#### Converting strings to objects

Crossplane converts JSON strings to objects.

Add {{<hover label="format" line="4">}}format: json{{</hover>}} to the
{{<hover label="format" line="1">}}convert{{</hover>}} object which is
the only supported string format for this conversion.

```yaml {label="format",copy-lines="all"}
- type: convert
convert:
toType: object
format: json
```

This conversion is useful for patching keys in an object. The following example
adds a tag to a resource with a customized key:

```yaml {label="format",copy-lines="all"}
- type: FromCompositeFieldPath
fromFieldPath: spec.clusterName
toFieldPath: spec.forProvider.tags
transforms:
- type: string
string:
type: Format
fmt: '{"kubernetes.io/cluster/%s": "true"}'
- type: convert
convert:
toType: object
format: json
```


#### Converting strings to arrays

Crossplane converts JSON strings to arrays.

Add {{<hover label="format" line="4">}}format: json{{</hover>}} to the
{{<hover label="format" line="1">}}convert{{</hover>}} object which is
the only supported string format for this conversion.

```yaml {label="format",copy-lines="all"}
- type: convert
convert:
toType: array
format: json
```

### Map transforms
The {{<hover label="map" line="6">}}map{{</hover>}} transform type
_maps_ an input value to an output value.
Expand Down Expand Up @@ -1505,7 +1556,6 @@ converts the input based on one of the following conversion types:
* `ToBase64` - Create a new base64 string from the input.
* `FromBase64` - Create a new text string from a base64 input.
* `ToJson` - Convert the input string to valid JSON.
* `FromJson` - Convert the input JSON string to an object.
* `ToSha1` - Create a SHA-1 hash of the input string.
* `ToSha256` - Create a SHA-256 hash of the input string.
* `ToSha512` - Create a SHA-512 hash of the input string.
Expand Down

0 comments on commit 961431d

Please sign in to comment.