Skip to content

--data flag does not accept json arrays #432

@reubenmiller

Description

@reubenmiller

The --data flag does not accept a valid json array. So it seems that somewhere along the lines the --data assumes it is only accepting either shorthand syntax (e.g. item.value=1) or a json object.

c8y api post /example --data '[{"fragment": "myTemp","series": "myT" }, {"fragment": "myWind","series": "mySpeed"} ]' --dry

Output

c8y api post /example --data '[{"fragment": "myTemp","series": "myT" }, {"fragment": "myWind","series": "mySpeed"} ]' --dry
2025-02-13T08:39:28.436+0100	ERROR	commandError: json error: data parameter does not contain valid json or shorthand json. Invalid shorthand JSON: Uneven number of key value pairs

Workaround

Use the --template flag instead as it accepts all valid json (as the templating language, jsonnet, is a superset of json, so it accepts both json and jsonnet syntax).

c8y api post /example --template '{"v":[{"fragment": "myTemp","series": "myT" }, {"fragment": "myWind","series": "mySpeed"} ]}' --dry

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions