Check whether any json input has a value null

Check whether any json input has a value null

Postby mahajan » Thu Jun 23, 2016 5:39 am

How to check whether any of the json input has value null using python?

Ex:
Code: Select all
{
    "status": 0,
    "pagingCriteria": {
        "pageSize": 10,
        "pageNumber": null,
        "sortOn": "candidateid",
        "sortBy": "asc"
    },
    "search": {
        "type": 2,
        "events": 1350,
        "jobs": [11963],
        "stages": [20022],
        "interviewers": [5896]
    }
}


In above json, i want to throw an error saying that "pageNumber cannot be null".

Can anybody help me.. Thank you
Last edited by micseydel on Thu Jun 23, 2016 7:22 am, edited 1 time in total.
Reason: Code tags. Initial post lock.
mahajan
 
Posts: 1
Joined: Thu Jun 23, 2016 5:21 am

Re: Check whether any json input has a value null

Postby Ofnuts » Thu Jun 23, 2016 7:43 am

Use the json module to read the json object into a Python dictionary (dictionary=json.loads(json_string)), and then test that the appropriate member (dictionary['pagingCriteria']['pageNumber']) is None.
This forum has been moved to http://python-forum.io/. See you there.
User avatar
Ofnuts
 
Posts: 2659
Joined: Thu May 14, 2015 9:46 am
Location: Paris, France, EU, Earth, Solar system, Milky Way, Local Cluster, Universe #32987440940987


Return to Web Development

Who is online

Users browsing this forum: No registered users and 1 guest

cron