내가 redis를 처음 접했기 때문에 REDIS에서 JSON의 요소에 액세스 할 수 있도록 아래에 복잡한 json을 저장하는 방법에 대한 지침이 필요합니다. -Python을 사용하여 Redis에서 복잡한 내포 된 JSON을 저장하는 방법
"Reservations": [
{
"Instances": [
{
"Monitoring": {
"State": "disabled"
},
"PublicDnsName": "",
"State": {
"Code": 16,
"Name": "running"
},
"EbsOptimized": "false",
"LaunchTime": "xxxxxxxxx",
"PrivateIpAddress": "x.x.x.x",
"ProductCodes": [],
"VpcId": "xxxxx",
"StateTransitionReason": "",
"InstanceId": "i-xxxxxxx",
"EnaSupport": "true",
"ImageId": "ami-xxxxx",
"PrivateDnsName": "ip-xxxxxx.ec2.internal",
"KeyName": "xxxxxxv",
"SecurityGroups": [
{
"GroupName": "xxx",
"GroupId": "sg-xxxx"
},
{
"GroupName": "xxxxxx",
"GroupId": "sg-xxxxx"
},
{
"GroupName": "xxxxx",
"GroupId": "sg-xxxxxx"
},
{
"GroupName": "xxxxx",
"GroupId": "sg-xxxxxx"
}
],
"ClientToken": "xxxxx",
"SubnetId": "subnet-xxxxx",
"InstanceType": "t2.micro",
"NetworkInterfaces": [
{
"Status": "in-use",
"MacAddress": "xxxxxxxx",
"SourceDestCheck": "true",
"VpcId": "vpc-xxxxx",
"Description": "",
"NetworkInterfaceId": "eni-xxxxx",
"PrivateIpAddresses": [
{
"PrivateDnsName": "ip-xx-ec2.internal",
"Primary": "true",
"PrivateIpAddress": "xxxxx"
}
],
"PrivateDnsName": "ip-xxxx-xx.ec2.internal",
"Attachment": {
"Status": "attached",
"DeviceIndex": 0,
"DeleteOnTermination": "true",
"AttachmentId": "eni-attach-xxxxx",
"AttachTime": "2017-0xxxxx"
},
"Groups": [
{
"GroupName": "xx",
"GroupId": "sg-xxxx"
},
{
"GroupName": "xxxx",
"GroupId": "sg-xxx"
},
{
"GroupName": "xxxx",
"GroupId": "sg-xxx"
},
{
"GroupName": "xxxx",
"GroupId": "sg-xxxx"
}
],
"Ipv6Addresses": [],
"OwnerId": "xxx",
"SubnetId": "subnet-xxxx",
"PrivateIpAddress": "1xxxx"
}
],
"SourceDestCheck": "true",
"Placement": {
"Tenancy": "default",
"GroupName": "",
"AvailabilityZone": "us-xxxxxxx"
},
"Hypervisor": "xen",
"BlockDeviceMappings": [
{
"DeviceName": "/dev/xxxxxx",
"Ebs": {
"Status": "attached",
"DeleteOnTermination": "true",
"VolumeId": "vol-xxxxxx",
"AttachTime": "2017-xxxxxxx"
}
}
],
"Architecture": "x86_64",
"RootDeviceType": "ebs",
"IamInstanceProfile": {
"Id": "xxxxxxxx",
"Arn": "arn:aws:iam::xxxxxxx"
},
"RootDeviceName": "/dev/xxxxx",
"VirtualizationType": "hvm",
"Tags": [
{
"Value": "xxxxxx",
"Key": "aws:cloudformation:stack-name"
},
{
"Value": "xxxxxxx",
"Key": "aws:cloudformation:logical-id"
},
{
"Value": "arn:aws:cloudformation:xxxxxx",
"Key": "aws:cloudformation:stack-id"
}
],
"AmiLaunchIndex": 0
}
],
"ReservationId": "r-xxxxx",
"RequesterId": "xxxxx",
"Groups": [],
"OwnerId": "xxxxxx"
}
]
}
JSON에있는 모든 요소를 가져 오기 위해 IP/호스트 이름/InstanceID를 쿼리하는 방식으로이 파일을 저장해야합니다.
위의 지침이 필요합니다.
아름답게 작동 –
내 입 : 밖으로 말을 툭, 난,하지만 질문이 있습니다 JSON의 태그 요소를 인쇄하려면 어떻게해야합니까? 아래에서 시도했지만 오류가 있습니다. 'print (r.jsonget ('obj ', Path ('. Reservations.Instances.Tags '))) ' –
@RohitSarkar ReJSON과 관련이 없으므로 경로가 잘못되었다고 생각합니다. 문서를 보면 알 수 있듯이'.Reservations [0] .Instances [0] .Tags' –