python - Get path of all the elements in dictionary -


i have dictionary in python , want path of values param1 or param2, ... replace these other values. value of param1 need ['optionsettings'][2]['value']. can have generic code this, print path of nodes/leaves below dictionary

{         "applicationname": "test",         "environmentname": "abc-nodejs",         "cnameprefix": "abc-neptune",         "solutionstackname": "64bit amazon linux 2016.03 v2.1.1 running node.js",         "optionsettings": [                            {                             "namespace": "aws:ec2:vpc",                             "optionname": "associatepublicipaddress",                             "value": "true"                             },                            {                             "namespace": "aws:elasticbeanstalk:environment",                             "optionname": "environmenttype",                             "value": "loadbalanced"                             },                            {                             "namespace": "aws:ec2:vpc",                             "optionname": "subnets",                             "value": "param1"                             },                            {                             "namespace": "aws:autoscaling:launchconfiguration",                             "optionname": "securitygroups",                             "value": "param2"                             },                            {                             "namespace": "aws:autoscaling:asg",                             "optionname": "minsize",                             "value": "1"                             },                            {                             "namespace": "aws:autoscaling:asg",                             "optionname": "maxsize",                             "value": "4"                             },                            {                             "namespace": "aws:autoscaling:asg",                             "optionname": "availability zones",                             "value": "any"                             },                            {                             "namespace": "aws:autoscaling:asg",                             "optionname": "cooldown",                             "value": "360"                             },                            {                             "namespace": "aws:autoscaling:launchconfiguration",                             "optionname": "iaminstanceprofile",                             "value": "neprole"                             },                            {                             "namespace": "aws:autoscaling:launchconfiguration",                             "optionname": "monitoringinterval",                             "value": "5 minutes"                             },                            {                             "namespace": "aws:autoscaling:launchconfiguration",                             "optionname": "rootvolumetype",                             "value": "gp2"                             },                            {                             "namespace": "aws:autoscaling:launchconfiguration",                             "optionname": "rootvolumesize",                             "value": "10"                             },                            {                             "namespace": "aws:elasticbeanstalk:sns:topics",                             "optionname": "notification endpoint",                             "value": "sunil.kumar2@pb.com"                             },                            {                             "namespace": "aws:elasticbeanstalk:hostmanager",                             "optionname": "logpublicationcontrol",                             "value": "false"                             },                            {                             "namespace": "aws:elasticbeanstalk:command",                             "optionname": "deploymentpolicy",                             "value": "rolling"                             },                            {                             "namespace": "aws:elasticbeanstalk:command",                             "optionname": "batchsizetype",                             "value": "percentage"                             },                            {                             "namespace": "aws:elasticbeanstalk:command",                             "optionname": "batchsize",                             "value": "100"                             },                            {                             "namespace": "aws:elasticbeanstalk:command",                             "optionname": "healthchecksuccessthreshold",                             "value": "ok"                             },                            {                             "namespace": "aws:elasticbeanstalk:command",                             "optionname": "ignorehealthcheck",                             "value": "false"                             },                            {                             "namespace": "aws:elasticbeanstalk:command",                             "optionname": "timeout",                             "value": "600"                             },                            {                             "namespace": "aws:autoscaling:updatepolicy:rollingupdate",                             "optionname": "rollingupdateenabled",                             "value": "false"                             },                            {                             "namespace": "aws:ec2:vpc",                             "optionname": "elbsubnets",                             "value": "param3"                             },                            {                             "namespace": "aws:elb:loadbalancer",                             "optionname": "securitygroups",                             "value": "param4"                             },                            {                             "namespace": "aws:elb:loadbalancer",                             "optionname": "managedsecuritygroup",                             "value": "param4"                             }                            ]  } 

this same question this:

print complete key path values of python nested dictionary

it necessary code. going need add handling of lists, since not presenting key/value structure, , can addressed question here:

how check if variable dictionary in python

which show how check type , modify behavior based on data type. easiest way accomplish set 2 dummy data types, 1 defined empty list , other empty map , perform "isinstance" checks of elements against dummy types decide on logic want execute.

between 2 of answers, should able build paths looking for.

lost right, not "write me" site.


Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -