admin管理员组

文章数量:1122846

I use ballerina to process composer.json files. such files have repositories entries like this:

"repositories": [
    {
        "type": "vcs",
        "url": ".git"
    },
    {
        "type": "vcs",
        "url": ".git"
    },
    ...
]

When such a json map is loaded in my ballerina script, the "type" field cannot be manipulated as other filed,

for example: this compiles:

string url = check theRepo.url.ensureType();

but this does not:

string type = check theRepo.type.ensureType();

the error is:

ERROR [dev_it.bal:(114:12,114:16)] invalid token 'type'
ERROR [dev_it.bal:(114:17,114:17)] missing identifier
ERROR [dev_it.bal:(114:33,114:33)] missing identifier
ERROR [dev_it.bal:(114:33,114:33)] missing semicolon token
ERROR [dev_it.bal:(114:33,114:37)] type definitions are allowed only at module level
ERROR [dev_it.bal:(114:37,114:38)] invalid token '.'

and my ballerina version is:

$bal --version
Ballerina 2201.10.3 (Swan Lake Update 10)
Language specification 2024R1
Update Tool 1.4.3

... I worked around it with this:


    theRepo["url"];
    theRepo["type"];

本文标签: Ballerina does not support quottypequot field in a json mapStack Overflow