From 3b58e158b3cd58e3a6cf43e8fd45812b70de0f47 Mon Sep 17 00:00:00 2001 From: Hasan Turken Date: Tue, 29 Aug 2023 10:53:37 +0300 Subject: [PATCH] Add support for convert from json to object/list Signed-off-by: Hasan Turken --- .../master/concepts/patch-and-transform.md | 55 ++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/content/master/concepts/patch-and-transform.md b/content/master/concepts/patch-and-transform.md index b859a8160..e9da99f12 100644 --- a/content/master/concepts/patch-and-transform.md +++ b/content/master/concepts/patch-and-transform.md @@ -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 @@ -1146,6 +1148,58 @@ suffix support. format: quantity ``` +#### Converting strings to objects + +Crossplane converts JSON strings to objects. + +Add {{}}format: json{{}} to the +{{}}convert{{}} object which is +the only supported string format for this conversion. + +```yaml {label="object",copy-lines="all"} +- type: convert + convert: + toType: object + format: json +``` + +{{< hint "tip" >}} +This conversion is useful for patching keys in an object. +{{< /hint >}} + +The following example adds a tag to a resource with a +{{}}customized key{{}}: + +```yaml {label="patch-key",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 {{}}format: json{{}} to the +{{}}convert{{}} object which is +the only supported string format for this conversion. + +```yaml {label="array",copy-lines="all"} +- type: convert + convert: + toType: array + format: json +``` + ### Map transforms The {{}}map{{}} transform type _maps_ an input value to an output value. @@ -1505,7 +1559,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.