Skip to content

null Safe select operator, aka. Optional_chaining #327

@He-Pin

Description

@He-Pin

refs: google/jsonnet#930
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining#optional_chaining_with_expressions

In JSONPath, we can select deeply, even it may be null.

  maybeNull: someObject?.innerObject?.whatIWant

I think we can support this with a ?. instead of ..

I have implemented it with :

      eval(
        """
          |local obj = {a: 1};
          |local obj2 = null;
          |obj2?.a
          |
          |""".stripMargin) ==> ujson.Null

or maybe just use std.get

This project is using this syntax https://github.com/jam01/xtrasonnet

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions