Bird
0
0

You want to parse a nested JSON string with JsonOutputParser like:

hard📝 Application Q8 of 15
LangChain - Output Parsers
You want to parse a nested JSON string with JsonOutputParser like:
{"user": {"name": "Eve", "roles": ["admin", "user"]}}

What will the parsed Python object look like?
A{'user': {'name': 'Eve', 'roles': ['admin', 'user']}}
B{"user": {"name": "Eve", "roles": ["admin", "user"]}}
CA flat dictionary with keys 'user.name' and 'user.roles'
DA list containing the user dictionary
Step-by-Step Solution
Solution:
  1. Step 1: Understand nested JSON parsing

    JsonOutputParser converts nested JSON objects into nested Python dictionaries and lists.
  2. Step 2: Map JSON structure to Python

    The nested JSON with 'user' key containing a dict with 'name' and 'roles' list becomes a nested Python dict with the same structure.
  3. Final Answer:

    {'user': {'name': 'Eve', 'roles': ['admin', 'user']}} -> Option A
  4. Quick Check:

    Nested JSON parses to nested dict/list [OK]
Quick Trick: Nested JSON becomes nested dicts and lists in Python [OK]
Common Mistakes:
  • Expecting flat dict with dot keys
  • Confusing JSON string with parsed object
  • Assuming output is a list instead of dict

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LangChain Quizzes