github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/docs/parser/create-array.md (about) 1 # `%[]` Create Array 2 3 > Quickly generate arrays 4 5 ## Description 6 7 `%[]` is a way of defining arrays in expressions and statements. Whenever a 8 `%[]` array is outputted as a string, it will be converted to minified JSON. 9 10 Array elements inside `%[]` can be whitespace and/or comma delimited. This 11 allows for compatibility with both Bash muscle memory, and people more 12 familiar with JSON. 13 14 Additionally you can also embed `a` style parameters inside `%[]` arrays too. 15 16 Like with YAML, strings in `%[]` do not need to be quoted unless you need to 17 force numeric or boolean looking values to be stored as strings. 18 19 20 21 ## Examples 22 23 ### Arrays passed as a JSON string: 24 25 ``` 26 » echo %[1..3] 27 [1,2,3] 28 29 » %[1..3] -> cat 30 [1,2,3] 31 ``` 32 33 ### Different supported syntax for creating a numeric array: 34 35 #### As a range 36 37 ``` 38 » %[1..3] 39 [ 40 1, 41 2, 42 3 43 ] 44 ``` 45 46 #### JSON formatted 47 48 ``` 49 » %[1,2,3] 50 [ 51 1, 52 2, 53 3 54 ] 55 ``` 56 57 #### Whitespace separated 58 59 ``` 60 » %[1 2 3] 61 [ 62 1, 63 2, 64 3 65 ] 66 ``` 67 68 #### Values and ranges 69 70 ``` 71 » %[1,2..3] 72 [ 73 1, 74 2, 75 3 76 ] 77 ``` 78 79 ### Strings: 80 81 #### barewords and whitespace separated 82 83 This will allow you to copy/paste lists from traditional shells like Bash 84 85 ``` 86 » %[foo bar] 87 [ 88 "foo", 89 "bar" 90 ] 91 ``` 92 93 #### JSON formatted 94 95 ``` 96 » %["foo", "bar"] 97 [ 98 "foo", 99 "bar" 100 ] 101 ``` 102 103 ### Special ranges 104 105 ``` 106 » %[June..August] 107 [ 108 "June", 109 "July", 110 "August" 111 ] 112 ``` 113 114 A full list of special ranges are available at [docs/mkarray/special](../mkarray/special.md) 115 116 ### Multiple expansion blocks: 117 118 ``` 119 » %[[A,B]:[1..4]] 120 [ 121 "A:1", 122 "A:2", 123 "A:3", 124 "A:4", 125 "B:1", 126 "B:2", 127 "B:3", 128 "B:4" 129 ] 130 ``` 131 132 ### Nested arrays: 133 134 ``` 135 » %[foo [bar]] 136 [ 137 "foo", 138 [ 139 "bar" 140 ] 141 ] 142 ``` 143 144 The `%` prefix for the nested array is optional. 145 146 ### JSON objects within arrays 147 148 ``` 149 » %[foo {bar: baz}] 150 [ 151 "foo", 152 { 153 "bar": "baz" 154 } 155 ] 156 ``` 157 158 The `%` prefix for the nested object is optional. 159 160 ## Detail 161 162 Murex supports a number of different formats that can be used to generate 163 arrays. For more details on these please refer to the documents for each format 164 165 * [Calendar Date Ranges](../mkarray/date.md): 166 Create arrays of dates 167 * [Character arrays](../mkarray/character.md): 168 Making character arrays (a to z) 169 * [Decimal Ranges](../mkarray/decimal.md): 170 Create arrays of decimal integers 171 * [Non-Decimal Ranges](../mkarray/non-decimal.md): 172 Create arrays of integers from non-decimal number bases 173 * [Special Ranges](../mkarray/special.md): 174 Create arrays from ranges of dictionary terms (eg weekdays, months, seasons, etc) 175 176 ## See Also 177 178 * [Special Ranges](../mkarray/special.md): 179 Create arrays from ranges of dictionary terms (eg weekdays, months, seasons, etc) 180 * [`"Double Quote"`](../parser/double-quote.md): 181 Initiates or terminates a string (variables expanded) 182 * [`%(Brace Quote)`](../parser/brace-quote.md): 183 Initiates or terminates a string (variables expanded) 184 * [`%{}` Create Map](../parser/create-object.md): 185 Quickly generate objects and maps 186 * [`'Single Quote'`](../parser/single-quote.md): 187 Initiates or terminates a string (variables not expanded) 188 * [`a` (mkarray)](../commands/a.md): 189 A sophisticated yet simple way to build an array or list 190 * [`expr`](../commands/expr.md): 191 Expressions: mathematical, string comparisons, logical operators 192 * [`ja` (mkarray)](../commands/ja.md): 193 A sophisticated yet simply way to build a JSON array 194 * [`ta` (mkarray)](../commands/ta.md): 195 A sophisticated yet simple way to build an array of a user defined data-type 196 197 <hr/> 198 199 This document was generated from [gen/parser/create_array_doc.yaml](https://github.com/lmorg/murex/blob/master/gen/parser/create_array_doc.yaml).