I am working on adding 'array wildcards' to a Go project on Github called jsonget. Here's an example of what I mean by array wildcards:
> echo "[{product:'coffee', price:2.10}, {product:'beer', price:3.80}]" | jsonget '*.price'
[2.10, 3.80]
The code for my branch is here
The problem I am running into is with typing, when GetValue
encounters a *
character, it recurses, calling GetValue
on the subexpression, but the type always comes back as a string.
For example, in the test file, I give it this piece of json:
{
"inventory": [
{"name": "mountain bike", "price": 251.0},
{"name": "red wagon", "price": 90.10},
{"name": "kinesis advantage", "price": 300.0},
{"name": "a ticket to Mars", "price": 1200000000.0}
]
}
Then query out inventory[*].price
, expecting [251,90.1,300,1.2e+09]
, but instead getting ["251","90.1","300","1.2e+09"]
.
I would like to avoid using reflection here, but I don't see another way to do this.