0

I have a following Json as an output and further need to organize the json in descending order of the sal value

[
     {
        "sal": 12,
        "Stack ": "Java",
        "EmpID": "00030010-0010-0000-0000-000000000121"
    },
    {
        "sal": 24,
        "Stack ": ".net",
        "EmpID": "00030010-0010-0000-0000-000000000144"
    },
    {
        "sal": 14,
        "Stack ": "Ruby",
        "EmpID": "00030010-0010-0000-0000-000000000198"
    }
]

please help me achieving the same

1

2 Answers 2

5

You can use the sorted built-in function using a specific key for sorting, like this:

sorted(list_of_dicts, key=lambda d: d['sal'], reverse=True)

Edit:

However, a question like this one was already answered here with some more options: https://stackoverflow.com/a/73050/6279885

Sign up to request clarification or add additional context in comments.

Comments

1

You can sort the JSON data based on the value of the sal key

data.sort(key=lambda x: x["sal"])

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.