Skip to content

Accessing fields with special characters

Problem / use case

You want to access fields with special characters such as periods (.), dashes (-), spaces (), or emojis, etc...

Solution - $d

You usually donโ€™t need to use $d to access data fields in DataPrime. Itโ€™s the default namespace, so fields like status_code are automatically interpreted as $d.status_code.

But in these cases with special characters using $d is required.

1. Field names with dots

If your field name includes a dot (.), DataPrime treats it as a nested path unless you use bracket notation. This can lead to unexpected behavior.

For example:

{
  "kubernetes.namespace": "dev",
  "kubernetes": {
    "namespace": "prod"
  }
}

To access the field with a literal dot in the name (kubernetes.namespace), use:

$d['kubernetes.namespace']

result

"dev"

To access the nested field inside the kubernetes object (kubernetes.namespace), use:

$d['kubernetes']['namespace']

result

"prod"

2. Field names with spaces

Dot notation doesnโ€™t support spaces. Use bracket notation:

choose $d['Total Salary']

3. Field names with emojis or non-ASCII characters

Fields with special characters require brackets:

create face from case_equals {
  $m.severity,
  DEBUG    -> '๐Ÿง',
  VERBOSE  -> '๐Ÿ˜ถโ€๐ŸŒซ๏ธ',
  INFO     -> '๐Ÿ™‚',
  WARNING  -> '๐Ÿ˜ฌ',
  ERROR    -> '๐Ÿ˜ฉ',
  CRITICAL -> '๐Ÿ’€',
  _          -> '๐Ÿคท'
}
| countby face as $d['๐Ÿ™‚'] into $d['# of times I made this face'] 

Output:
"๐Ÿ™‚""# of times I made this face"
๐Ÿ’€17275
๐Ÿ˜ฉ55821
๐Ÿ˜ฌ13084
๐Ÿ˜ถโ€๐ŸŒซ๏ธ318376
๐Ÿ™‚2958063
๐Ÿง3727783