Repository navigation
-F doesn't parse JSON object inside an array #8621
Description
Activity
- addedgh-apirelating to the gh api commandrelating to the gh api commandenhancementa request to improve CLIa request to improve CLIand removedbugSomething isn't workingSomething isn't working
on Feb 20, 2024 I've relabelled this as an
enhancementbecause I don't believe it's documented anywhere that we would expect this to work. Here are the docs for-Fand-f:-F, --field key=value Add a typed parameter in key=value format -f, --raw-field key=value Add a string parameter in key=value formatWhile we might hope that
-Fhandles json, it doesn't, and that's what this enhancement request is really about.I did a naive implementation for
-Fsupport in a3ade6b which attempts to unmarshal the field as JSON, but I'm not sure what the pitfalls of this approach are (for example, what is valid json?).- addedhelp wantedContributions welcomeContributions welcomeand removedneeds-triageneeds to be reviewedneeds to be reviewed
on Feb 20, 2024 @williammartin These are all valid JSONs:
999,true,false,null,"foo". So, I don't think it's really safe.Maybe moving the JSON unmarshal part to the end of the method could help (where the input is not of any other expected type)?
I know it's not that pretty, but can't we just add a new argument, like
--json-field, for such cases? This doesn't break CLI compatibility and also provides the desired improvements.I've relabelled this as an
enhancementbecause I don't believe it's documented anywhere that we would expect this to work. Here are the docs for-Fand-f:-F, --field key=value Add a typed parameter in key=value format -f, --raw-field key=value Add a string parameter in key=value formatWhile we might hope that
-Fhandles json, it doesn't, and that's what this enhancement request is really about.I did a naive implementation for
-Fsupport in a3ade6b which attempts to unmarshal the field as JSON, but I'm not sure what the pitfalls of this approach are (for example, what is valid json?).This would be really useful to be documented on the api docs . If you use -F with a bool for the value it fails with the value must be a string or an array. Only after trying -f, found from this issue, did it work.
Maybe an extra set of properties to update in the example
-F "properties[][property_name]=is_for_abc" -f "properties[][value]=true"Please open a Documentation Issue against the CLI example here Create or update custom property values for a repository. Knowing that -f/-F would not work would have saved me several hours of time.
Yes I'm a little stubborn, and could have switched to curl.. but I wanted to stick with a single method.- addedenhancementa request to improve CLIa request to improve CLIand removedenhancementa request to improve CLIa request to improve CLIhelp wantedContributions welcomeContributions welcome
on Feb 27, 2025
Describe the bug
gh version 2.42.1 (2024-01-15)
https://github.com/cli/cli/releases/tag/v2.42.1
For this Custom Properties endpoint, we need to pass a JSON with an array of objects. But neither the
-for the-Foptions parse that subobject, and it's always sent as a string, which is rejected by the endpoint.Steps to reproduce the behavior
Expected vs actual behavior
Debug:
In the request body, we'd expect an array of objects:
instead of an array of strings
Workaround
@williammartin figured out a workaround with
--input:although it would still be desirable that
-Funderstand json, as we have the alternative of-fif we want to pass the string unparsed. Today both behave the same for this input.