0

This is my sample code:

   st = loadedJSON

    if len(value) == 1:
        x = st[value[0]]['sample']

    elif len(value) == 2:
        x = st[value[0]][value[1]]['sample']

    elif len(value) == 3:
        x = st[value[0]][value[1]][value[2]]['sample']

I'm not sure how to convert this code into something like:

value = ["1","2","3","4","5","6"]
st = loadedJSON
y = len(value)
# Need to create like this
x = st["1"]["2"]["3"]["4"]["5"]["6"]['sample']
# Bigger VALUE = Bigger JSON Keys Path

Is it any specific function that converts ARRAY to JSON Key Path?

0

1 Answer 1

1

Something like this?

node = st
for step in value:
    node = node[step]
x = node['sample']
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.