| --- |
| title: Specifying JSON within Command-Line Options |
| --- |
| |
| <!-- |
| Licensed to the Apache Software Foundation (ASF) under one or more |
| contributor license agreements. See the NOTICE file distributed with |
| this work for additional information regarding copyright ownership. |
| The ASF licenses this file to You under the Apache License, Version 2.0 |
| (the "License"); you may not use this file except in compliance with |
| the License. You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
| --> |
| |
| Some `gfsh` commands allow JSON specifications within some options. |
| These JSON strings specify initialization properties in the form of |
| key/value pairs. |
| |
| A JSON string is appended to a fully qualified class name, |
| for those classes that implement the `Declarable` interface. |
| The parameter to the interface's `init` method is an |
| object that contains initialization properties. |
| The JSON string is parsed and broken into a set of |
| property names and values that define the object. |
| |
| The specification of a cache loader class in the `gfsh create region` |
| command may have a JSON specification. |
| For example, |
| |
| ``` |
| gfsh>create region --name=region1 --type=PARTITION \ |
| --cache-loader=com.example.Setup{'k1':'v1','k2':'v2','k3':'v3'} |
| ``` |
| |
| The JSON string in this example is |
| |
| ``` pre |
| {'k1':'v1','k2':'v2','k3':'v3'} |
| ``` |
| |
| The JSON string is surrounded by curly braces, and the pairs |
| are separated by commas. |
| Each pair is separated by a colon. |
| Each of the two strings that define a pair |
| is enclosed with single or double quote characters. |
| Be consistent throughout the JSON string in the use of |
| either single or double quote characters. |
| |
| Space characters separate `gfsh` command-line options, |
| and the tokenizing of the options occurs before the parsing |
| of JSON strings. |
| If the value within the command-line option contains a space, |
| delimit it with double quote marks. |
| |
| As an example, assume that there is a single pair, and the |
| value of the pair is `value with space`. |
| The right-hand side of the `--cache-loader` example option becomes |
| |
| ``` |
| gfsh>create region --name=region2 --type=PARTITION \ |
| --cache-loader="com.example.Setup{'k1':'value with space'}" |
| ``` |
| |
| To incorporate a single quote character within a value, |
| escape it with two backslash characters. |
| For example, |
| |
| ``` |
| gfsh>create region --name=region3 --type=PARTITION \ |
| --cache-loader="com.example.Setup{'k1':'property\\'s value'}" |
| ``` |
| |
| The value of the pair is `property's value`. |