Hi, there!
I'm trying to convert the result of AWS CloudWatch Logs Insights, but I can't.
Like this:
{
"results": [
[
{
"field": "@timestamp",
"value": "2020-02-03 15:03:26.315"
},
{
"field": "@message",
"value": "some messages 1"
},
{
"field": "@ptr",
"value": "xxx"
}
],
[
{
"field": "@timestamp",
"value": "2020-02-03 15:03:27.495"
},
{
"field": "@message",
"value": "some messages 2"
},
{
"field": "@ptr",
"value": "xxx"
}
]
],
"statistics": {
"recordsMatched": 887.0,
"recordsScanned": 887.0,
"bytesScanned": 101532.0
},
"status": "Complete"
}
To this:
[
[ "2020-02-03 15:03:26.315", "some messages 1" ],
[ "2020-02-03 15:03:27.495", "some messages 2" ]
]
Can anyone help me?
I feel really dumb, but can't seem to figure out how to transform this:
{
"Foo": "somekey",
"Bar": "somevalue"
}
into:
{ "somekey": "somevalue" }
the closest I can get is like:
{ Foo : Bar }
but that yields:
{
"Foo": "somevalue"
}
so it's the key in the hash part I cant figure out how to get
(I want to make the new hash's key, the value of an existing key in the input hash)
so I have read somewhere this may not be possible w/ stock JMESPath
Jmespath does not allow to use dynamic names in multi select hashes.
but there is some extension:
https://github.com/grofers/go-codon/wiki/Jmespath-extensions#5-support-for--expressions-as-key-when-performing-multi-select-hash
(wanted to be able to do this in aws cli --query )
{animal: {ant: 1, bee: 2, cat: 3}, vegetable: {apple: 4, banana: 5}, mineral: {axe: 6, bell; 7}}
into [{key1: "animal", key2: "ant", value: }, {key1: "animal", key2: "bee", value: 2}, ... {key1: "mineral", key2: "bell", value: 7}]
composer require aws/aws-sdk-php
Using version ^3.133 for aws/aws-sdk-php
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Installation request for mtdowling/jmespath.php (installed at 2.4.0) -> satisfiable by mtdowling/jmespath.php[2.4.0].
- aws/aws-sdk-php 3.133.0 requires mtdowling/jmespath.php ^2.5 -> satisfiable by mtdowling/jmespath.php[2.5.0].
- aws/aws-sdk-php 3.133.1 requires mtdowling/jmespath.php ^2.5 -> satisfiable by mtdowling/jmespath.php[2.5.0].
- aws/aws-sdk-php 3.133.10 requires mtdowling/jmespath.php ^2.5 -> satisfiable by mtdowling/jmespath.php[2.5.0].
- aws/aws-sdk-php 3.133.11 requires mtdowling/jmespath.php ^2.5 -> satisfiable by mtdowling/jmespath.php[2.5.0].
- aws/aws-sdk-php 3.133.2 requires mtdowling/jmespath.php ^2.5 -> satisfiable by mtdowling/jmespath.php[2.5.0].
- aws/aws-sdk-php 3.133.3 requires mtdowling/jmespath.php ^2.5 -> satisfiable by mtdowling/jmespath.php[2.5.0].
- aws/aws-sdk-php 3.133.4 requires mtdowling/jmespath.php ^2.5 -> satisfiable by mtdowling/jmespath.php[2.5.0].
- aws/aws-sdk-php 3.133.5 requires mtdowling/jmespath.php ^2.5 -> satisfiable by mtdowling/jmespath.php[2.5.0].
- aws/aws-sdk-php 3.133.6 requires mtdowling/jmespath.php ^2.5 -> satisfiable by mtdowling/jmespath.php[2.5.0].
- aws/aws-sdk-php 3.133.7 requires mtdowling/jmespath.php ^2.5 -> satisfiable by mtdowling/jmespath.php[2.5.0].
- aws/aws-sdk-php 3.133.8 requires mtdowling/jmespath.php ^2.5 -> satisfiable by mtdowling/jmespath.php[2.5.0].
- aws/aws-sdk-php 3.133.9 requires mtdowling/jmespath.php ^2.5 -> satisfiable by mtdowling/jmespath.php[2.5.0].
- Conclusion: don't install mtdowling/jmespath.php 2.5.0
- Installation request for aws/aws-sdk-php ^3.133 -> satisfiable by aws/aws-sdk-php[3.133.0, 3.133.1, 3.133.10, 3.133.11, 3.133.2, 3.133.3, 3.133.4, 3.133.5, 3.133.6, 3.133.7, 3.133.8, 3.133.9].
Installation failed, deleting ./composer.json.
composer why --tree mtdowling/jmespath
to see why it is locked to 2.4.0
locations[0].state == 'NY' && 'a' || 'b'
search
to work in the opposite way? I mean, instead to search
a key:value, to exclude the key:value passed and return all the rest
{"peers": {"ns1.sys.cloudsys.tmcs": {"delay": [ 0.476, 0.371 ]}, "insert": { "10.75.33.5": { "delay": [ 0.384 ]}}, "delete": {"ns2.sys.cloudsys.tmcs": { "delay": [ 0.465 ]}}}
insert
and delete
, is it possible to do with wildcards? kind of peer.[insert|delete]
?
interfaceStatus
I can do interfaces.*.interfaceStatus
and I get the right result, however I lose Ethernet47
so I am not sure to which interface the interfaceStatus
belongs to"Ethernet48": {
"lastStatusChangeTimestamp": [
1580496491.6286151,
1580496491.6286182
]
},
"Ethernet47": {
"lastStatusChangeTimestamp": [
1580496491.629291,
1582706128.6775026
],
"interfaceStatus": [
"connected",
"disabled"
]
}
.*.
and get back the value of * where jmspath match
There is an official repo (the web site / test suite ones), but I'm not the maintainer (who hasn't responded to some issues for several years), so I don't know who should take responsibility.
FWIW, I've forked the official documentation site (so I can host it with TLS) and the JS implementation for GorillaStack, and I'm maintaining my own specification additions in the doc site and the JS implementation.
See:
https://github.com/gorillastack/jmespath.js
https://github.com/gorillastack/jmespath.site