Skip to content

Latest commit

 

History

History
184 lines (100 loc) · 5.16 KB

passing-json-parameters-on-the-command-line-899fe34.md

File metadata and controls

184 lines (100 loc) · 5.16 KB

Passing JSON Parameters on the Command Line

Depending on the shell you use, the escaping rules are different. Here you'll find examples of correct escaping and quotes when passing JSON objects on the command line using different shells.

The table below gives an overview of the escaping rules in these commonly used shells. VALUE refers to one single line in json.

Shell

Correct Escaping and Quotes

Bash

Use --parameter "VALUE" and escape quotes with \" within VALUE

or

Use --parameter 'VALUE' and do not escape quotes within VALUE

Windows Command Prompt

Use --param "VALUE" and escape quotes with \" within VALUE

Windows PowerShell

Use --param "VALUE" and escape quotes with \" within VALUE

Tip:

The CLI client provides examples in the command help for all commands. The examples that include JSON parameters use formatting that is compliant with Bash (Unix/Linux operating system, macOS) and Windows Command Prompt.

The command-line examples in this chapter are based on the following JSON:

{
    "Key1": ["Value1"],
    "Key2": ["Value1", "Value2"]
}

Option 1

--parameter "{\"Key1\":[\"Value1\"],\"Key2\":[\"Value1\", \"Value2\"]}"

For example, when creating a subaccount (btp create accounts/subaccount) with labels Department = Sales and Contacts = name1@example.com and name2@example.com, use the following syntax:

Sample Code:

btp create account/subaccount --display-name "my-subaccount" --region us10 --subdomain "my-subdomain" --labels "{\"Department\":[\"Sales\"],\"Contacts\":[\"name1@example.com\", \"name2@example.com\"]}"

Option 2

--parameter '{"Key1": ["Value1"], "Key2": ["Value1", "Value2"]}'

For example, when creating a subaccount (btp create accounts/subaccount) with labels Department = Sales and Contacts = name1@example.com and name2@example.com, use the following syntax:

Sample Code:

btp create account/subaccount --display-name "my-subaccount" --region us10 --subdomain my-subdomain --labels '{"Department": ["Sales"],"Contacts": ["name1@example.com", "name2@example.com"]}'
--parameter "{\"Key1\":[\"Value1\"],\"Key2\":[\"Value1\", \"Value2\"]}"

For example, when creating a subaccount (btp create accounts/subaccount) with labels Department = Sales and Contacts = name1@example.com and name2@example.com, use the following syntax:

Sample Code:

btp create account/subaccount --display-name "my-subaccount" --region us10 --subdomain "my-subdomain" --labels "{\"Department\":[\"Sales\"],\"Contacts\":[\"name1@example.com\", \"name2@example.com\"]}"
--parameter '{\"Key1\":[\"Value1\"],[\"Key2\":\"Value1\", \"Value2\"]}'

For example, when creating a subaccount (btp create accounts/subaccount) with labels Department = Sales and Contacts = name1@example.com and name2@example.com, use the following syntax:

Sample Code:

./btp create account/subaccount --display-name "my-subaccount" --region us10 --subdomain my-subdomain --labels '{\"Department\":[\"Sales\"],\"Contacts\":[\"name1@example.com\", \"name2@example.com\"]}'

You can also transfer JSON parameters by providing the full path to a JSON file. For example:

btp create services/binding --name my-binding-name --instance-name my-service-instance-name --parameters "<your-user-directory>/Documents/parameters.json"

Related Information

Command Syntax of the btp CLI

Working with Global Accounts, Directories, and Subaccounts Using the btp CLI

Working with External Resource Providers Using the btp CLI

Working with Environments Using the btp CLI