我正在使用JQ解析Salesforce CLI返回的JSON。 我的bash脚本是:
orgCreateResult=$(sfdx force:org:display -u mockScreenOrg --json)
orgCreateStatus=$(echo $orgCreateResult | ./bash-scripts/jq-win64.exe .status -r)
echo "orgCreateResult: "
echo "$orgCreateResult"
echo "orgCreateStatus: $orgCreateStatus"
instanceUrl=$(echo $checkDevHubResult | ./bash-scripts/jq-win64.exe .result -r)
echo "instanceUrl: $instanceUrl"
我在Windows的VS Code中使用bash终端。我从此脚本得到的输出是:
orgCreateResult:
{
"status": 0,
"result": {
"username": "test-******@example.com",
"devHubId": "****@**.com",
"id": "************",
"createdBy": "*****@**.com",
"createdDate": "2019-05-13T14:15:32.000+0000",
"expirationDate": "2019-06-12",
"status": "Active",
"edition": "Developer",
"orgName": "HPESC",
"accessToken": "************************************",
"instanceUrl": "https://nosoftware-ruby-2532-dev-ed.cs6.my.salesforce.com",
"clientId": "PlatformCLI",
"alias": "mockScreenOrg"
}
}
orgCreateStatus: 0
instanceUrl:
我能够从JSON读取状态字段,但对于结果对象有点失败。我想从JSON读取instanceUrl字段,以便稍后在脚本中使用。不知道我做错了什么。我对bash和JQ非常陌生
答案 0 :(得分:0)
尝试一下:
instanceUrl=$(echo $orgCreateResult | ./bash-scripts/jq-win64.exe .result.instanceUrl -r)