Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Json data validation
#1
Hi ,

I have json file like below
{
"fieldname" :{ "name" :"str",
                "age" : 13
                "add" : "str"
                "out" :"Y",
                 "result" :"Y",
"nextfield" :{ "req" :"Y",
              "cfy" : "nan",},
"nextfield1": { "req" :"n",
               "source" :"n/a",
                "target" :"n/a"}
}
like there are many json file, jus 1 json im putting here.

here name, age, add , out , result are mandatory keys .. and nextfield and nextfield1 are optional keys have to do validation for these , like chk the mandatory keys present in input file , if not present should throw exeption mandatory keys not present, same like optional .. also have to validate the values of mandatory keys
suppose if i check the type of name (mandatory keys) should print the type of value. likewise i have to do validation of nextfield and nextfield1 , if req key is "Y" then it will go this field n chk if req : N it will throw error msg ,

kindly suggest how i can achieve this ?
Reply
#2
that looks like a pure dictionary, not json

to read a json file:

import json

with open('jsonfile') as fp:
    mydata = json.load(fp)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  encrypt data in json file help jacksfrustration 1 233 Mar-28-2024, 05:16 PM
Last Post: deanhystad
  data validation with specific regular expression shaheen07 0 346 Jan-12-2024, 07:56 AM
Last Post: shaheen07
  Read nested data from JSON - Getting an error marlonbown 5 1,383 Nov-23-2022, 03:51 PM
Last Post: snippsat
  Reading Data from JSON tpolim008 2 1,099 Sep-27-2022, 06:34 PM
Last Post: Larz60+
  Convert nested sample json api data into csv in python shantanu97 3 2,857 May-21-2022, 01:30 PM
Last Post: deanhystad
  Struggling with Juggling JSON Data SamWatt 7 1,904 May-09-2022, 02:49 AM
Last Post: snippsat
  json api data parsing elvis 0 936 Apr-21-2022, 11:59 PM
Last Post: elvis
  Capture json data JohnnyCoffee 0 1,205 Nov-18-2021, 03:19 PM
Last Post: JohnnyCoffee
  Serializing Python data Correctly (JSON) JgKSuperstar 4 2,124 Nov-04-2021, 07:31 PM
Last Post: JgKSuperstar
  input data validation plumberpy 2 1,789 Aug-11-2021, 12:04 PM
Last Post: plumberpy

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020