Flatten an array in substation v1.1.0 #155
-
Hi @jshlbrd How can I flatten an array in substation v1.1.0. Similar to this processor in v0.9.1 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hey @viraj-lunani, the flatten processor wasn't migrated to v1.0 since it's supported natively by Substation's JSON parser (GJSON). You can flatten sub.tf.object.copy({object: {source_key: 'b|@flatten', target_key: 'b'}}) If you need to extend often, then you could build a custom transform Jsonnet function like: extend(source, target): [
// This appends the value from `source` to the end of `target`.
sub.tf.object.copy({object: {source_key: source, target_key: target + '.-1' }}),
sub.tf.object.copy({object: {source_key: target + '|@flatten', target_key: target}}),
], If you want to try GJSON in the browser, then you can use their playground site. The flatten modifier works for valid JSON without keys as well (e.g. sub.tf.object.copy({object: {source_key: '@this|@flatten'}}) |
Beta Was this translation helpful? Give feedback.
Hey @viraj-lunani, the flatten processor wasn't migrated to v1.0 since it's supported natively by Substation's JSON parser (GJSON). You can flatten
{"b":["val3","val4",["val1","val2"]]}
by using a copy transform and the GJSON@flatten
modifier. Try this:If you need to extend often, then you could build a custom transform Jsonnet function like:
If you w…