Skip to content

[berry] How to access nested json objects. #22540

Answered by sfromis
chromoxdor asked this question in Q&A
Discussion options

You must be logged in to vote

I'd recommend against doing any JSON parsing at the string level, to instead do all the processing at the map level, much less code than trying to take apart strings.

"Discovering" what elements are in a map, including nested maps, is based on the keys() function on a map.
If you simply want the first key: object_name = payload_json.keys()()
What happens here is that keys() returns an iterator function, and calling that function once will return the first available value.

You can also iterate through a plain map with a construct like:

  for key : payload_json.keys()
    var value = payload_json[key]
    print(key, value)
  end

And here's an example of a more generalized construct for tra…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@chromoxdor
Comment options

@sfromis
Comment options

@chromoxdor
Comment options

Answer selected by chromoxdor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants