Generating Formatted JSON

If you receive the message "Parameter 'parameter_name' must be in JSON format," then your JSON formatting isn't correct. The following methods help you format the data correctly.

JSON Format for a Single Complex Type Option Value

If an option is complex type, then you can generate the JSON format for that option value by using the --generate-param-json-input option. The argument for the --generate-param-json-input option is the name of the option for which you want the JSON format, without the -- option specifier. For example, the following command shows the JSON format to use to specify route rules (--route-rules option) for a route table:

network route-table update --generate-param-json-input route-rules
[
  {
    "cidrBlock": "string",
    "description": "string",
    "destination": "string",
    "destinationType": "string",
    "networkEntityId": "string"
  },
  {
    "cidrBlock": "string",
    "description": "string",
    "destination": "string",
    "destinationType": "string",
    "networkEntityId": "string"
  }
]

Values that you provide in the option argument replace any existing values. For example, if you already have an ingress rule and you want to add an egress rule, you must specify both the existing ingress rule and the new egress rule. If you specify only the rule that you want to add, any previously existing rules will be gone. Similarly, to add a policy statement or add values for a defined tag, for example, you must respecify the existing statements or values that you want to keep in addition to what you want to add.

Sometimes the output contains a message about choices, such as in the following example:

oci compute instance launch --generate-param-json-input source-details
[
  "This parameter should actually be a JSON object rather than an array - pick one of the
  following object variants to use",
  {
    "bootVolumeId": "string",
    "sourceType": "bootVolume"
  },
  {
    "bootVolumeSizeInGBs": 0,
    "imageId": "string",
    "kmsKeyId": "string",
    "sourceType": "image"
  }
]

When you use the Compute Web UI to create an instance, you select either a Custom Image or a Boot Volume. Similarly, the message in the preceding example tells you to specify either the boot volume block or the image block, not both.

JSON Format for Values of All Options of a Command

The --generate-full-command-json-input option shows JSON format for values of all options of the specified command, including values that aren't complex values.

oci network route-table update --generate-full-command-json-input > route_table_update.json

Use the --from-json option to pass in your customized version of this output.

oci network route-table update --from-json file://route_table_update.json

JSON Format of Existing Values

If resources of this type already exist, do a get or list of the resources to see the JSON formatting and also to check the current values.

oci network route-table get --rt-id ocid1.routetable.unique_ID

Copy the block you want directly from this output, and then change the values as needed.

In the case where multiple values are allowed, use this method to avoid overwriting values that you want to keep. Copy the block you want from the get or list output, and then change, add, or delete values as needed.