Skip to content

Coalescing operator ( ?? ) not recognized #16

Description

@wbrco

When using the Coalescing operator in a jsonata file, the program returns:

$ jsonata -i sampledata.json -e useableJsonata -o finaloutput.json
JSONata error at useableJsonata:21.40
The symbol "?" cannot be used as a unary operator

                "startTime": $c.start ?? $c.dialTime,

Jsonata:

(
    $goodapi := $filter($, function($o){
        ($o.direction = "outbound" and $not($exists($o.recordingToken))
        or ($o.direction = "inbound" and $o.status = "connected" and $not($exists($o.recordingToken))))});
    $rec := $filter($, function($o){$exists($o.recordingToken)});

    $grout := $map($goodapi, function($c){
        {
            "requestInfo": {
                "requestId": $c.sourceChannel
            },
            "CallOverview": {
                "callId": $c.callDetailKey,
                "owner": $c.sourceName,
                "callType": "BusinessVoice+",
                "direction": $c.direction,
                "stopReason": $c.status = "connected" ? "hangup" : "unsuccessful"
            },
            "voiceRecords": {
                "startTime": $c.start ?? $c.dialTime,
                "stopTime": $c.end ?? $c.dialtTime,
                "timeZone": "EDT"
            },
            "participants": [
                {
                    "name": $c.sourceName,
                    "phone": $c.sourceid,
                    "identityType": $length($c.sourceid) > 4 ? "external" : "internal"
                },
                { 
                    "name": $c.destinationName,
                    "phone": $c.destinationid,
                    "identityType": $length($c.destiantionid) > 4 ? "external" : "internal"
                }
            ] 
        }
    });
)

Sample Data:

[
  {
    "sourceid": "8260",
    "sourceChannel": "a3a61ba1-0000-0000-0000-000092d6571a",
    "start": 1783544759000,
    "destinationid": "7030",
    "destinationName": "User One",
    "callDetailKey": 21911938268,
    "end": 1783544769000,
    "sourceName": "User Two",
    "status": "connected",
    "dialTime": 1783544753000,
    "direction": "outbound"
  },
  {
    "sourceid": "16266169762",
    "sourceChannel": "7c5fdab7-0000-cc4-0000-0000dceff547",
    "destinationid": "5006",
    "destinationName": "User Three",
    "callDetailKey": 21911925116,
    "sourceName": "User Four",
    "status": "Not Answering",
    "dialTime": 1783544504000,
    "direction": "inbound"
  },
  {
    "sourceid": "4351",
    "sourceChannel": "b2ca44be-0000-0000-0000-000058297747",
    "start": 1783540785000,
    "destinationid": "4830",
    "destinationName": "User Five",
    "callDetailKey": 21911657637,
    "end": 1783540797000,
    "sourceName": "User Six",
    "status": "connected",
    "dialTime": 1783540781000,
    "direction": "inbound"
  }
]

Works fine in try.jsonata.org.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions