Lab - JSON PATH - Wild Cards

can someone pls clarify the difference of these two JSON path query? One with the ‘’ sign, the other without this sign

task 2, i got two different results
alpine-host ~ ➜ cat input.json | jpath ‘$[0,4]’
[
“Apple”,
“Facebook”
]

alpine-host ~ ➜ cat input.json | jpath $[0,4]
[
“Facebook”
]

task 1, i got the same result
alpine-host ~ ➜ cat input.json | jpath ‘$[0]’
[
“Apple”
]
alpine-host ~ ➜ cat input.json | jpath $[0]
[
“Apple”
]

FYI
alpine-host ~ :heavy_multiplication_x: cat input.json
[
“Apple”,
“Google”,
“Microsoft”,
“Amazon”,
“Facebook”,
“Coca-Cola”,
“Samsung”,
“Disney”,
“Toyota”,
“McDonald’s”
]

A couple of issues.

First, please paste your code using “code blocks”; the forum software will garble a program by putting in smart quotes. This is not very smart of the software, but it is what it is. In any event, your data before it gets garbled is:

[
"Apple",
"Google",
"Microsoft",
"Amazon",
"Facebook",
"Coca-Cola",
"Samsung",
"Disney",
"Toyota",
"McDonald’s"
]

Second, the reason that you get different results when you don’t use single quotes (') is that the $ sign also means something to Unix shells, and if you don’t use single quotes, it will garble your query before jpath can see it. So you need to quote your command to jpath with single quotes.

thanks Rob for prompt explanations

i’m going for CKA, just wanted to play with JSON Path as it’s part of the curriculum.

First, please paste your code using “code blocks”–>Is that www.codeblocks.org?

No; on this site you can enter text with Markdown, so I mean the Markdown features for entering text, like using “```” for starting a code block. You want to use that, because this site filters text in weird ways that don’t make for correct code :slight_smile:

Good idea to learn jsonpath, although the syntax for jpath and Kubernetes’ jsonpath feature differs subtly. Look at the official doc page, which will tell you what Kubernetes implements, and what it does not.

That said: jq and jpath are good pieces of software that are worth learning, jq in particular. But everybody’s version of this is a little different, so you need to be aware of the differences.