github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/docs/commands/struct-keys.md (about)

     1  # `struct-keys`
     2  
     3  > Outputs all the keys in a structure as a file path
     4  
     5  ## Description
     6  
     7  `struct-keys` outputs all of the keys in a structured data-type eg JSON, YAML,
     8  TOML, etc.
     9  
    10  The output is a JSON array of the keys with each value being a file path
    11  representation of the input structure's node.
    12  
    13  ## Usage
    14  
    15  ```
    16  <stdin> -> struct-keys [ depth ] -> <stdout>
    17  
    18  <stdin> -> struct-keys [ flags ] -> <stdout>
    19  ```
    20  
    21  ## Examples
    22  
    23  The source for these examples will be defined in the variable `$example`:
    24  
    25  ```
    26  » set json example={
    27        "firstName": "John",
    28        "lastName": "Smith",
    29        "isAlive": true,
    30        "age": 27,
    31        "address": {
    32            "streetAddress": "21 2nd Street",
    33            "city": "New York",
    34            "state": "NY",
    35            "postalCode": "10021-3100"
    36        },
    37        "phoneNumbers": [
    38            {
    39                "type": "home",
    40                "number": "212 555-1234"
    41            },
    42            {
    43                "type": "office",
    44                "number": "646 555-4567"
    45            },
    46            {
    47                "type": "mobile",
    48                "number": "123 456-7890"
    49            }
    50        ],
    51        "children": [],
    52        "spouse": null
    53    }
    54  ```
    55  
    56  Without any flags set:
    57  
    58  ```
    59  » $example -> struct-keys
    60  [
    61      "/lastName",
    62      "/isAlive",
    63      "/age",
    64      "/address",
    65      "/address/state",
    66      "/address/postalCode",
    67      "/address/streetAddress",
    68      "/address/city",
    69      "/phoneNumbers",
    70      "/phoneNumbers/0",
    71      "/phoneNumbers/0/type",
    72      "/phoneNumbers/0/number",
    73      "/phoneNumbers/1",
    74      "/phoneNumbers/1/number",
    75      "/phoneNumbers/1/type",
    76      "/phoneNumbers/2",
    77      "/phoneNumbers/2/type",
    78      "/phoneNumbers/2/number",
    79      "/children",
    80      "/spouse",
    81      "/firstName"
    82  ]
    83  ```
    84  
    85  Defining max depth and changing the separator string:
    86  
    87  ```
    88  » $example -> struct-keys --depth 1 --separator '.'   
    89  [
    90      ".children",
    91      ".spouse",
    92      ".firstName",
    93      ".lastName",
    94      ".isAlive",
    95      ".age",
    96      ".address",
    97      ".phoneNumbers"
    98  ]
    99  ```
   100  
   101  An example of a unicode character being used as a separator:
   102  
   103  ```
   104  » $example -> struct-keys --depth 2 --separator ☺                                                                                                                                                           
   105  [
   106      "☺age",
   107      "☺address",
   108      "☺address☺streetAddress",
   109      "☺address☺city",
   110      "☺address☺state",
   111      "☺address☺postalCode",
   112      "☺phoneNumbers",
   113      "☺phoneNumbers☺0",
   114      "☺phoneNumbers☺1",
   115      "☺phoneNumbers☺2",
   116      "☺children",
   117      "☺spouse",
   118      "☺firstName",
   119      "☺lastName",
   120      "☺isAlive"
   121  ]
   122  ```
   123  
   124  Separator can also be multiple characters:
   125  
   126  ```
   127  » $example -> struct-keys --depth 1 --separator '|||' 
   128  [
   129      "|||firstName",
   130      "|||lastName",
   131      "|||isAlive",
   132      "|||age",
   133      "|||address",
   134      "|||phoneNumbers",
   135      "|||children",
   136      "|||spouse"
   137  ]
   138  ```
   139  
   140  ## Flags
   141  
   142  * `--depth`
   143      How far to traverse inside the nested structure
   144  * `--separator`
   145      String to use as a separator between fields (defaults to `/`)
   146  * `-d`
   147      Alias for `--depth`
   148  * `-s`
   149      Alias for `--separator`
   150  
   151  ## See Also
   152  
   153  * [`[ Index ]`](../parser/item-index.md):
   154    Outputs an element from an array, map or table
   155  * [`[[ Element ]]`](../parser/element.md):
   156    Outputs an element from a nested structure
   157  * [`formap`](../commands/formap.md):
   158    Iterate through a map or other collection of data
   159  * [`set`](../commands/set.md):
   160    Define a local variable and set it's value
   161  
   162  <hr/>
   163  
   164  This document was generated from [builtins/core/datatools/structkeys_doc.yaml](https://github.com/lmorg/murex/blob/master/builtins/core/datatools/structkeys_doc.yaml).