# Help macro for safe navigate dynamics using runtime string

**URL:** <https://community.haxe.org/t/help-macro-for-safe-navigate-dynamics-using-runtime-string/4609>\
**Category:** Haxe\
**Tags:** macro\
**Created:** [May 8, 2025, 5:41pm UTC](https://community.haxe.org/t/help-macro-for-safe-navigate-dynamics-using-runtime-string/4609 "2025-05-08T17:41:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![neimanpinchas](https://community.haxe.org/user_avatar/community.haxe.org/neimanpinchas/32/2348_2.png) [@neimanpinchas](https://community.haxe.org/u/neimanpinchas)\
**Post date:** [May 8, 2025, 5:41pm UTC](https://community.haxe.org/t/help-macro-for-safe-navigate-dynamics-using-runtime-string/4609/1 "2025-05-08T17:41:05Z")

</div>

I am try to make possible and safe to navigate dynamics using runtime strings,  
The first is working, second not.

```haxe
		var a:Dynamic = {

				b: {
					c: 123
				}

		};
    var aaa=safeget(a.b.c);
    trace(aaa);
    aaa=safeget(a["b"].c);
    trace(aaa);

```

Error

```haxe
 14 | aaa=safeget(a["b"].c);
    | ^^^
    | String should be Int

```

Live example, and macro code;

> **[Try Haxe!](https://try.haxe.org/#34BCDAe7)**
>
> Haxe is an amazing multiplatform programming language. Check it out !

````haxe
var getexpr = switch expr.expr {
    case EField(e, f):{
      //var safe_e=safeget(e);
      macro $e?.$f;
  }
    case EArray(e1,e2):{
            macro $e1==null ? null : Reflect.field($e1,$e2);
    }
    ```
````

---

<div class="post-metadata">

**Author:** ![filt3rek](https://community.haxe.org/user_avatar/community.haxe.org/filt3rek/32/2613_2.png) [@filt3rek](https://community.haxe.org/u/filt3rek)\
**Post date:** [May 30, 2025, 9:56am UTC](https://community.haxe.org/t/help-macro-for-safe-navigate-dynamics-using-runtime-string/4609/2 "2025-05-30T09:56:18Z")

</div>

Hej,

Something like that should work : [Try Haxe!](https://try.haxe.org/#1bcb3dd9)
