Answer is: kubectl get pv --sort-by=.spec.capacity.storage > /opt/outputs/sto . . .

Dar Nattp:
Answer is: kubectl get pv --sort-by=.spec.capacity.storage > /opt/outputs/storage-capacity-sorted.txt
My Answer is : kubectl get pv --sort-by=.items[*].spec.capacity > /opt/outputs/storage-capacity-sorted.txt

Why my answer is incorrect?
Why not include .items[*] ?


Dar Nattp:


unnivkn:
Hi @Dar Nattp I would say, please go through this small course, it’s well explained there:
https://kodekloud.com/courses/json-path-quiz/

Leo Pastor:
@Dar Nattp basically because “.items[*].spec.capacity(.storage)” is a pattern for a query to list of (potentially many) storage capacities of the PVs, not a single criteria to be considered for sorting, and it is used in a JSONPATH query for that purpose.
On the other hand, “.spec.capacity.storage” is a single parameter (or key or variable), which can be used as a criteria for sorting the output by a process called by “–sort-by”.
The link mentioned by @unnivkn is highly recommended for proper use of those expressions.

PS: That is why you get nothing on 2nd command on your first output, and therefore the system marks answer as incorrect.
Try to correlate the above concepts with your screenshots, including the jsonpath online evaluator.

Aneek Bera:
JSON path