Skip to content

Need Help in Python Jason load #3982

@ashishsme14

Description

@ashishsme14

We had given a task and for which we written below code, while executing it showing an error. Please let us know where we went wrong in coding-

import os
import json

def func1(value):
    a=json.loads(value)    
    b = json.dumps(a, indent=1)
    return b

if __name__ == "__main__":    
    try:
        data=input()
        b=func1(data)
        print(True)
        print(b[1].values())
    except ValueError as error:
        print(False)

After executing it we are getting as -

Compiler Message

Runtime Error
Error (stderr)

Traceback (most recent call last):
  File "Solution.py", line 14, in <module>
    print(b[1].values())
AttributeError: 'str' object has no attribute 'values'

Input (stdin)
[{"1": "Student1", "Marks": 90}, {"2": "Student2", "Marks": 95}]

Your Output (stdout)
True

Expected Output

True
dict_values(['Student2', 95])

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions