Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data Transformation Utilities Using JSON Schemas #16

Closed
benjagm opened this issue Feb 27, 2023 · 44 comments
Closed

Data Transformation Utilities Using JSON Schemas #16

benjagm opened this issue Feb 27, 2023 · 44 comments

Comments

@benjagm
Copy link
Collaborator

benjagm commented Feb 27, 2023

Brief Description
JSON Schema is designed for validation, but the information in a schema can be used to for a number of other purposes. One of those purposes is data transformation. This project aims to implement some of the transformation uses cases JSON Schema Community has been asking about the last months.

Expected Outcomes

Provide an implementation of the following utilities in any language. They should work with at least the latest version of JSON Schema. Tests should be described in JSON so others who want to write a similar tool in a different language can easily use your tests to ensure compatibility.

  • Provide a utility that takes a JSON Schema and a JSON document and adds to the document any values that are missing but have a default specified for that value in the JSON Schema.
  • Provide a utility that takes a JSON Schema and a JSON document and removes properties in the JSON document that are not described in the JSON Schema.
  • Provide a utility that takes a JSON Schema and a query string from a form post (application/x-www-form-urlencoded) and convert the string to JSON using the JSON Schema to know the types for the values.
    • For example, the string ?foo=1 with schema { "properties": { "foo": { "type": "number" } } } should return { "foo": 1 } rather than { "foo": "1" }.

Skills Required

  • A basic understanding of JSON Schema

Mentors
@jdesrosiers

Project Repo: tbd

Expected Difficulty
Easy

Expected Time Commitment
175

@affaannn
Copy link

@benjagm plzz assign me this issue

@jansche
Copy link
Contributor

jansche commented Feb 28, 2023

Hi @affaannn,
there will be an application process by Google Summer of Code starting March 20. Before that, you will be able to introduce yourself and perform initial qualifying tasks. We'll let you all know here, so stay tuned.
Cheers
Jan

@affaannn
Copy link

Hi @affaannn,

there will be an application process by Google Summer of Code starting March 20. Before that, you will be able to introduce yourself and perform initial qualifying tasks. We'll let you all know here, so stay tuned.

Cheers

Jan

Aight thank you
Soo exited . Can't wait to work on it

@VishrutAggarwal
Copy link

Hi,

Hope you're doing well. I have been looking at the project ideas for GSoC and this one really intrigues me. I am confident that my skills and experience make me an ideal candidate for this project.

I have a strong understanding of JSON Schema and its applications. I am comfortable working with many programming languages such as JavaScript, C++, Python and Java to name a few and can implement the required utilities using the latest version of JSON Schema. I have experience in writing tests in JSON, and I understand the importance of ensuring compatibility with different languages.

The expected outcomes of the project are exciting, and I am particularly interested in providing a utility that takes a JSON Schema and a query string from a form post and converts it to JSON using the JSON Schema to know the types for the values. I believe that my experience in developing web applications and working with JSON data will be beneficial in achieving success in this area.

I am fully committed to this project and can dedicate at least 175 hours to it. I am excited about the opportunity to contribute to this project and learn from the mentors.

Looking forward to more details about how one can contribute to this project.

@ishaan812
Copy link

@jansche where can we find the initial qualifying tasks? Have they been added or yet to be added.

@ankit-pn
Copy link

ankit-pn commented Mar 1, 2023

Hello everyone,

I am a 3rd year Computer Science student at NIT Bhopal, India. Over the past few years, I have worked on several Node.js projects and gained experience working with JSON schema. I am familiar with the utilities need that has been described in this project and these are some of utilities that even I wanted for my personal use in my projects.

Having developed the backend of several applications using Node.js, I am excited to take on the challenge of implementing all the utilities mentioned above as a GSoC mentee this summer. I am looking forward to completing the initial qualifying tasks and working with the community.

Thank you.

@affaannn
Copy link

affaannn commented Mar 3, 2023

Hello Everyone
I hope you all are doing well. My name is Md Affan, and I'm a student of B.tech Mechanical at Jamia Millia Islamia.

I'm reaching out to express my interest in contributing to Postman's GSOC 2023.
I liked Data Transformation Utilities Using JSON Schemas idea. I have experience working with Python and C++, and I'm familiar with JSON Schema, and I'm excited about the potential of this project to transform the way that developers work with API data.
I'm also open to working on other areas of the project where there is a need.

I have already studied the project documentation and guidelines and I have set up the development environment on my local machine. I would greatly appreciate any guidance or assistance that you can provide in getting started with contributing to the project.

I actually hve some questions regarding this idea and also abput application process of GSOC2023

  1. How does the project handle JSON Schema files with complex dependencies or circular references?

  2. Are there any performance considerations to keep in mind when working with large JSON documents or schemas?

  3. Are there any planned or potential future features or enhancements for the project, such as support for additional schema formats or transformation operations?

  4. Is it okay if I learn while coding phase as I am not familiar with some tech stacks used in this organization,if yes plzz suggest me some topics that I should learn.

  5. What are initial qualifying tasks ,and when we will get that to solve?

@Atish03
Copy link

Atish03 commented Mar 3, 2023

Hello Everyone,
I am Atish Shah, pursuing B.Tech in Engineering Physics (Sophomore) at IIT(ISM) Dhanbad. According to the description of the project, this seems to be an easy task and having been worked on several projects which included schema handling, I think I am perfectly qualified for this task and would like to contribute to this project. Waiting eagerly for the qualifying tasks.
Thank You.

@Atish03
Copy link

Atish03 commented Mar 3, 2023

Hey @benjagm, Do we need to introduce ourselves by answering the questions mentioned in Guide here itself ?

@benjagm
Copy link
Collaborator Author

benjagm commented Mar 3, 2023

Hi folks,
we're currently coordinating with mentors and will provide more details as well as answer questions beginning of next week (week of March 6). Please bear with us.
Best regards.
Ben

@jdesrosiers
Copy link
Collaborator

Hi everyone 👋. Thanks for your interest in this project. I'd like to invite everyone to join the JSON Schema slack to get involved with the community. It's a great place to ask questions or discuss JSON Schema. If you're new to JSON Schema, have a look at Understanding JSON Schema.

@jdesrosiers
Copy link
Collaborator

A little more about this project ...

For this project, you won't be contributing code to an existing application or library, you'll be the maintainer of a new library in the JSON Schema ecosystem. You can write it in any language you like, but you'll probably want to use existing components wherever possible. For example, the JavaScript library @hyperjump/json-schema (that I maintain) has utilities for working with JSON Schemas so you can focus on solving the problem at hand rather than having to build a whole new JSON Schema implementation.

@dellamora
Copy link

dellamora commented Mar 7, 2023

Hi,

I'm Francielle Dellamora, a 21yo Brazilian web developer passionate about TypeScript.

This project interested me because it uses technologies I am already familiar with and because it is similar to Zod, so I think it will be a fun programming challenge and an excellent opportunity to further my knowledge of schema validation

you can learn more about me on my website or @francidellamora (:

@benjagm
Copy link
Collaborator Author

benjagm commented Mar 8, 2023

Hi everyone! Thanks a lot for your interest in this project Idea and JSON Schema! We'd like to run an Office Hours Session tomorrow at 09:00 PST, 18:00 CET, 22:30 IST, 14:00 BRT
This is the link to join: https://www.google.com/url?q=https://postman.zoom.us/j/87665681860?pwd%3DcjZkVnA1MHpWMFR0eXV6bS8raDN3UT09&sa=D&source=calendar&ust=1678707171237791&usg=AOvVaw1q9uGbTtKTLdK0y4ZbOIY0

In the meantime we invite you to join JSON Schema Slack server in the channel #gsoc-2023 using this link: https://join.slack.com/t/json-schema/shared_invite/zt-1qnbilvie-_Tvbr6YQL29l2HZBNvCiDQ

@dellamora @Atish03 @affaannn @ankit-pn @VishrutAggarwal @ishaan812
@jdesrosiers

@segun-codes
Copy link

segun-codes commented Mar 8, 2023

Hi Everyone,

My name is Segun Adodo, I have a background in Information System. This particular GSoC project idea catches my fancy and I would be happy to contribute. Given that I am proficient and comfortable programming in Java and JavaScript, I believe I am suitably positioned to successfully deliver the project if given the opportunity. I am happy to bring my software development experience to bear on this project.

One thing that interests me in this project is the opportunity to learn about JSON Schema (and perhaps other concepts/techniques/tools, not as obvious to me at the moment) as I haven't had any reason to use or study about it before. Another key attraction, is the excitement, sense of purpose and feeling of accomplishment that comes with building open-source utilities that can be used by anyone and anywhere in the world for free.

My mentors and project coordinators can derive the best from me by providing guidance especially when I request for one, but most importantly, leaving me to mostly figure out things on my own works well for me since I learn better this way. Whilst working with your organization, I will be studying Python programming language but without impacting my timing and deliverables commitment to this project. This undertaking is already incorporated in my personal development plan for the period long before now.

I prefer to simplify my experience when working on projects to encourage productivity. For instance, I'd rather use intuitive project folder structure, git for version control, task manager to track tasks and calendar reminders to avoid losing track of delivery/meetings timelines. I am more comfortable organizing my tasks into small bits that are measurable and highly suggestive of my progress. It offers me some psychological good this way.

I look forward to the qualifying task as well as sharing a proposal on project delivery weekly schedule complete with associated milestones and deliverables. Many thanks!!!

@ishaan812
Copy link

ishaan812 commented Mar 9, 2023

Hey guys,
I'm Ishaan Shah, an engineering undergraduate majoring in IT based out of Mumbai, India. I love working with new technologies and learning new things. Most recently I have been working on a building a fintech platform with a stealth startup mostly working on the backend primarily with Golang but I have a fair bit of knowledge about Javascript, TypeScript, Python and always looking to learn new things.

Just a few weeks ago, I was trying to setup Snowplow Analytics for our platform and trying to figuring out its complex setup locally. Which is when I came across the self described schemas for enrichment that they used. I was quite interested about how the enrichment process worked. I did not quite look into it back then. Then I was just looking for GSOC projects I would like to contribute to and found this. JSON Schema was what they were using for their process. Also working with a giant codebase with multiple languages on multiple surfaces connected by a lot of REST API's. I have understood how much the consistency of type safety which JSON schema helps with across languages is so important. How much easier it makes the debugging process and improves the communication between languages. Data Transformations, just as an example adding default values would be super helpful to further enhance the scope of this project and lower the boilerplate backend code required and I would love to play a part in that.

I have for the most part, always worked remotely with teams. The necessity to over communicate in such an environment and adhering to the process becomes even more important to enhance efficiency. Also the need of well made documentation cannot be understated. I like to clearly communicate about my tasks and have a clear plan before I can get going on it on my own and start coding. I like to take ownership of the tasks provided to me.

By the time GSOC begins, I wont be committed to any other major work since it will be in the middle of my summer break. So I will be able to provide the time necessary for the execution of this project.

I take a lot of pride in my setup and organization, you will never catch me working on VSCode with Prettify and all the beautification you can get, along with nice folder structures. Among other non-development tools, I'm a big TO-DO list guy who likes to get notifications about every small event in the day since I tend to forget. For that I use Todoist.

@semioz
Copy link

semioz commented Mar 10, 2023

Greetings, everyone! My name is Semih, and I'm thrilled to be here to share my passion for software development. As a freshman software student, I have been working on various backend projects using technologies like JavaScript, TypeScript, Node.js, MongoDB, Redis and PostgreSQL. I also have familiarity in front-end technologies such as HTML, CSS, and React.js.

In addition to my technical skills, I have been actively contributing to the community as a Postman Student Expert for a year. My role involves helping students with APIs and Postman, and this experience has helped me develop my teamwork, communication, and problem-solving skills.

In summary, I am a passionate and motivated MIS student with a keen interest in backend engineering. I am excited about the opportunity to work on the GSoC 2023 project on JSON Schema data transformation where I am planning to implement this project using JavaScript and Ajv. I am committed to delivering high-quality and efficient implementations of the requested utilities, and I look forward to the opportunity to work with the mentors and the community to achieve this goal.

@TarunAlapati-git
Copy link

Hello everyone! My name is Tarun, a pre final year student from BITS Pilani, India. I find this project very interesting as JSON Schema is a widely-used format for defining the structure and content of JSON data. By building data transformation utilities that use JSON schemas, this project provides a powerful way to manipulate and transform JSON data.

The project's emphasis on data transformation tools shows that it is intended to address real-world issues that developers and data analysts confront. This implies that a variety of real-world situations are likely to benefit from the code and tools created via this initiative.By itself, JSON schemas are an effective tool for data validation and documentation. This project has the ability to enhance the quality of the data and decrease mistakes in downstream processes by utilising the benefits of JSON schemas in the data transformation process.

As mentors and project coordinators you can get the best out of me by providing clear project goals and expectations,provide detailed information and context,give feedback and correction when required.As i will be working on this project during my summer break,i can allot as much time as needed. I keep myself organized my having a schedule to do my dialy tasks using tools such as notion,google calender etc.

Looking forward to contribute to this project and learning a ton working with the mentors.

@jdesrosiers
Copy link
Collaborator

jdesrosiers commented Mar 10, 2023

Hi everyone. Thanks again for your interest in this project. In the contributor guidance document, it mentions picking up a "first issue" task for the project and "mandatory qualification task". However, that only makes sense for contributing to an existing project and this project will be built from scratch. Creating a repo and setting it up for development, testing, publishing, and contributions will all be a part of your responsibilities. So, I came up with a qualification task that we can do without a repo or any code.

Qualification Task

Provide a test case that can be used as an acceptance test for any of the transformation operations described in the project description. This test should be expressed in JSON and include the inputs and expected output for the transformation operation. You can post your tests in this thread. Look over the tests others have posted before you and make sure someone hasn't already posted something testing the same thing. You can show that you understand the complexities you'll face with this project by coming up with a non-trivial test case.

Example for applying defaults

{
  "description": "Given a schema with a default set for the 'foo' property",
  "schema": {
    "type": "object",
    "properties": {
      "foo": {
        "type": "number",
        "default": 42
    }
  },
  "tests": [
    {
      "description": "When the schema is applied to an empty object, the 'foo' property should be set to the default value",
      "instance": {},
      "expected": {
        "foo": 42
      }
    },
    {
      "description": "When the schema is applied to an object where 'foo' exists, the 'foo' property should not change",
      "instance": { "foo": 3 },
      "expected": {
        "foo": 3
      }
    }
  ]
}

@Atish03
Copy link

Atish03 commented Mar 10, 2023

HI everyone, My name is Atish Shah, I am pursuing Bachelor of Technology in Engineering Physics at Indian Institute of Technology Dhanbad, India and am currently a Sophomore.

The thing that interests me the most about this project is its usefulness and Importance. JSON Schema are essential for data validation and structuring the data as intended by various applications. I like the idea of providing the API with some data and getting out an uniform output, like providing it with URL encoded data and getting out structured and useful data out of it.

As a mentor, you just have to provide me with a clear result and I will make sure to get that as efficiently and effectively as possible.

Since I will be working on this project in my summer break, there wont be any interference with the project and I would be able to commit all my time to this project.

I like working in daytime and finishing my projects at least reasonable time before the deadline. As for the tools I use to keep myself organised, I use Tasks, Google Calendar and for projects I use Docker and GitHub.

I am very excited to contribute to this project and am looking forward for some inputs from mentors.

@Atish03
Copy link

Atish03 commented Mar 10, 2023

@jdesrosiers, we just have to provide with a json object like

{
      "description": "When the schema is applied to an object having string value to 'foo', the 'foo' property should be a number",
      "instance": { "foo": "42" },
      "expected": {
          "invalid" : "Expected number but got string"
       }
}

as a test case here, Right ?

@benjagm
Copy link
Collaborator Author

benjagm commented Mar 10, 2023

Hi everyone!! Thanks a lot for your interest in JSON Schema ideas.

We invite you to join JSON Schema Slack server in the channel #gsoc-2023 Join the server using this link

In #gson-2023 channel you will find there: 1)resources, 2)recording of the last office hours session, 3)clear instructions to prepare your submission to this Project Idea and 4) the best place to get immediate support.

JSON Schema is all about Community and the Community is in Slack! See you there!

@jdesrosiers
Copy link
Collaborator

@Atish03 No, your submission should look more like my example. You should provide a schema that will produce interesting behavior (hopefully more interesting than the simple one I used) and include at least one example of how that schema would transform one or more instances. Also, don't forget to tell me which transformation your tests are covering: filling in defaults, removing additional keywords, etc.

EVERYONE: If you have questions, let's do that on slack. Then you can come here to post your submissions. That way people don't need to wade through a bunch of discussion to see what others have submitted.

@semioz
Copy link

semioz commented Mar 10, 2023

This is my test case for the qualification task where it includes a "language" property and an "information" property.


{
    "description": "Given a schema with a 'language' property and a 'information' property",
    "schema": {
        "type": "object",
        "properties": {
            "language": {
                "type": "string"
            },
            "information": {
                "type": "string",
                "mapFrom": "language"
            }
        },
        "patternProperties": {
            "^language[0-9]*$": {
                "type": "string"
            },
            "^information[0-9]*$": {
                "type": "string"
            }
        }
    },
    "tests": [{
            "description": "When the schema is applied to an object with a value for 'language', the 'information' property should be set to the corresponding language information",
            "instance": { "language": "javascript" },
            "expected": {
                "language": "javascript",
                "information": "dynamically-typed"
            }
        },
        {
            "description": "When the schema is applied to an object without a value for 'language', the 'information' property should not be created",
            "instance": { "otherProperty": "value" },
            "expected": {
                "otherProperty": "value"
            }
        },
        {
            "description": "When an unsupported language is specified, the 'information' property should not be created",
            "instance": { "language": "Holy-C" },
            "expected": { "language": "Holy-C" }
        },
        {
            "description": "When there are multiple language properties, each one should map to its corresponding information",
            "instance": {
                "language1": "TypeScript",
                "language2": "Python"
            },
            "expected": {
                "language1": "TypeScript",
                "information1": "Superset of JavaScript",
                "language2": "Python",
                "information2": "Created by Guido Van Rossum"
            }
        },
        {
            "description": "When the schema is applied to an object with a null value for 'language', the 'information' property should not be created",
            "instance": { "language": null },
            "expected": {}
        },
        {
            "description": "When the schema is applied to an object with a value for 'language' that has leading or trailing white space, the 'information' property should still be created and mapped correctly",
            "instance": { "language": "  Golang  " },
            "expected": {
                "language": "Golang",
                "information": "Open-source programming language developed at Google"
            }
        }
    ]
}

@TarunAlapati-git
Copy link

TarunAlapati-git commented Mar 10, 2023

Test case for applying defaults with some of the properties as required.

 {
    "description": "Given a schema with defaults set for some properties",
    "schema": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string",
          "default": "John Doe"
        },
        "age": {
          "type": "integer",
          "default": 25
        },
        "email": {
          "type": "string",
          "format": "email",
          "default": "example@example.com"
        }
      },
      "required": ["name", "age"]
    },
    "tests": [
      {
        "description": "When the schema is applied to an empty object, any missing properties (irrespective of requirement) should be filled with default values",
        "document": {},
        "expected_result": {
          "name": "John Doe",
          "age": 25,
          "email": "example@example.com"
        }
      },
      {
        "description": "When the schema is applied to an object where some properties exist, the missing properties with default values should be filled in and the existing properties should not change",
        "document": {
          "name": "Jane Smith",
          "email": "jane@example.com"
        },
        "expected_result": {
          "name": "Jane Smith",
          "age": 25,
          "email": "jane@example.com"
        }
      },
      {
        "description": "When the schema is applied to an object with all values filled in, the document should remain unchanged",
        "document": {
          "name": "Jane Smith",
          "age": 35,
          "email": "jane@example.com"
        },
        "expected_result": {
          "name": "Jane Smith",
          "age": 35,
          "email": "jane@example.com"
        }
      }
    ]
  }

@TarunAlapati-git
Copy link

TarunAlapati-git commented Mar 10, 2023

Test case for removing properties from JSON document not described in the schema.

{
    "description": "Given a JSON Schema and a JSON document, removes properties in the JSON document that are not described in the JSON Schema.",
    "schema": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string"
        },
        "age": {
          "type": "integer"
        }
      }
    },
    "tests": [
      {
        "description": "When the schema is applied to an empty object, it just returns the same empty object",
        "document": {},
        "expected_result": {}
      },
      {
        "description": "Here email is not defined in the schema hence removed",
        "document": {
          "name": "Jane Smith",
          "email": "jane@example.com"
        },
        "expected_result": {
          "name": "Jane Smith"
        }
      },
      {
        "description": "age should not be removed even if it is not as per schema",
        "document": {
          "name": "Jane Smith",
          "age": "35"
        },
        "expected_result": {
          "name": "Jane Smith",
          "age":"35"
        }
      }
    ]
  }

@segun-codes
Copy link

segun-codes commented Mar 11, 2023

Here's my solution to the qualification task. It applies defaults.

{
    "description": "Given a schema with properties, 'name', 'yrs_of_exp' and 'qualified'",
    "schema": {
        "type": "object",
        "properties": {
	    "name": {"type": "string", "minLength": 5, "maxLength": 30, "default": "Unnamed"},
	    "yrs_of_exp": {"type": "integer", "minimum": 13, "exclusiveMaximum": 21, "default": 20},
	    "qualified": {"type": "string", "default": "over-qualified"}
	}
    },
    "tests": [
        {
            "description": "When the schema is applied to an empty object, set the 'name', 'yrs_of_exp' and 'qualified' properties to 'Unnamed', 20 and 'over-qualified' respectively",
            "instance": {},
            "expected": {
	        "name": "Unnamed",
		"yrs_of_exp": 20,
		"qualified": "over-qualified"
	    }		
        },
	{
            "description": "When the schema is applied to an object with property 'yrs_of_exp' having value greater than 20 but with missing property 'qualified', set property 'qualified' to 'over-qualified'",
            "instance": {
	        "name": "Segun",
		"yrs_of_exp": 24,
            },
            "expected": {
	        "name": "Segun", 
		"yrs_of_exp": 24,
		"qualified": "over-qualified"
	    }		
        },
	{
            "description": "When the schema is applied to an object having property 'name' and property 'qualified' set to 'over-qualified', set property 'yrs_of_exp' to 20",
            "instance": {
	        "name": "Obinna",
		"qualified": "over-qualified"
	    },
            "expected": {
	        "name": "Obinna",
		"yrs_of_exp": 20,
	        "qualified": "over-qualified"
	    }		
        }
    ]
}

@VishrutAggarwal
Copy link

Here are the test cases I cooked up:


{
    "description": "Given a query string from a form post, convert the string to JSON",
    "schema": {
        "type": "object",
        "properties": {
            "name": {
                "type": "string"
            },
            "age": {
                "type": "number"
            }
        }
    },
    "tests": [
        {
            "description": "When the schema is applied to an empty string, the JSON object comes out as empty object",
            "instance": "",
            "expected": {}
        },
        {
            "description": "When the schema is applied to a string from form post, a JSON object is formed with corresponding type of value",
            "instance": "?age=21",
            "expected": {
                "age": 21
            }
        },
        {
            "description": "When the schema is applied to a string from form post with no matching property, a JSON object is formed with values defaulted to string type",
            "instance": "?foo=21&bar=hello",
            "expected": {
                "foo": "21",
                "bar": "hello"
            }
        },
        {
            "description": "When the schema is applied to a string from form post with multiple queries, some of which have a matching property while rest do not, a JSON object is formed with corresponding type of values for defined properties and rest are defaulted to string",
            "instance": "?name=vishrut&age=21&foo=bar",
            "expected": {
                "name": "vishrut",
                "age": 21,
                "foo": "bar"
            }
        },
        {
            "description": "When the schema is applied to a string from form post with multiple queries, a JSON object is formed with corresponding type of values",
            "instance": "?name=vishrut&age=21",
            "expected": {
                "name": "vishrut",
                "age": 21
            }
        }
    ]
}

Here's my thought and work process:

  1. Looked through the test cases provided in this thread and the ones given in the repo.
  2. Chose one of the transformation operations: taking the input query string from a form post and converting it into a JSON object.
  3. Considered basic test cases without introducing many constraints to keep it simple.
  4. Formulated a schema and wrote the test cases.
  5. The test cases would include:
  • An empty string
  • A string with a single query which is defined in the schema
  • A string with multiple queries defined in the schema
  • A string with queries which are not defined in the schema
  • A string with queries, some of which are defined in the schema and the rest are not
  1. Consider more test scenarios, to be implemented later if form post query string returns errors, like:
  • A string with multiple queries of the same property

@saip007
Copy link

saip007 commented Mar 11, 2023

Hello Community & @jdesrosiers,
I'm Sai Prashanth, pursuing 4th year B.Tech in Computer Science and Engineering. also Jr Software Engineer at LoginSoft | OpenSource Beginner. I can code in Python [Intermediate] and have some experience in web as well. I had an experience working with experience JSON in my previous project where my work is to scrape the different sites, collect data and Store in JSON Schema. this is my QUALIFICATION TASK .

adds default values to a JSON
This test case includes the following scenarios:

A nested property ("address") with its own default values
A missing required property ("age")
A property with a value different from its default ("name")
A missing property with a default value ("email")
A missing nested property ("city" and "state") with default values
A nested property with some values missing ("city" and "state") and others with different values ("street" and "zip")

This should cover most of the edge cases and scenarios that may arise when transforming a JSON document based on a JSON Schema with default values.

{

 "schema": {
   "type": "object",
   "properties": {
     "name": {
       "type": "string",
       "default": "John"
     },
     "age": {
       "type": "number",
       "default": 25
     },
     "email": {
       "type": "string",
       "default": "example@example.com"
     },
     "address": {
       "type": "object",
       "properties": {
         "street": {
           "type": "string",
           "default": "123 Main St."
         },
         "city": {
           "type": "string",
           "default": "Anytown"
         },
         "state": {
           "type": "string",
           "default": "CA"
         },
         "zip": {
           "type": "string",
           "default": "12345"
         }
       }
     }
   },
   "required": ["name", "age"]
 },
 "document": {
   "name": "Alice",
   "address": {
     "street": "456 Elm St.",
     "zip": "54321"
   }
 },
 "expectedOutput": {
   "name": "Alice",
   "age": 25,
   "email": "example@example.com",
   "address": {
     "street": "456 Elm St.",
     "city": "Anytown",
     "state": "CA",
     "zip": "54321"
   }
 }
}

test case for removing properties in a JSON document that are not described in the JSON Schema

{
  "input": {
    "name": "John Smith",
    "age": 35,
    "email": "john@example.com"
  },
  "schema": {
    "type": "object",
    "properties": {
      "name": { "type": "string" },
      "age": { "type": "number" }
    },
    "required": ["name"]
  },
  "expectedOutput": {
    "name": "John Smith",
    "age": 35
  }
}

In this test case, the input JSON document has a property called "email" which is not described in the JSON Schema. The expected output JSON document should have the "email" property removed. The utility should only keep the properties that are described in the JSON Schema.

looking foreword for Suggestions/feedback.

Hi everyone. Thanks again for your interest in this project. In the contributor guidance document, it mentions picking up a "first issue" task for the project and "mandatory qualification task". However, that only makes sense for contributing to an existing project and this project will be built from scratch. Creating a repo and setting it up for development, testing, publishing, and contributions will all be a part of your responsibilities. So, I came up with a qualification task that we can do without a repo or any code.

Qualification Task

Provide a test case that can be used as an acceptance test for any of the transformation operations described in the project description. This test should be expressed in JSON and include the inputs and expected output for the transformation operation. You can post your tests in this thread. Look over the tests others have posted before you and make sure someone hasn't already posted something testing the same thing. You can show that you understand the complexities you'll face with this project by coming up with a non-trivial test case.

Example for applying defaults

{
  "description": "Given a schema with a default set for the 'foo' property",
  "schema": {
    "type": "object",
    "properties": {
      "foo": {
        "type": "number",
        "default": 42
    }
  },
  "tests": [
    {
      "description": "When the schema is applied to an empty object, the 'foo' property should be set to the default value",
      "instance": {},
      "expected": {
        "foo": 42
      }
    },
    {
      "description": "When the schema is applied to an object where 'foo' exists, the 'foo' property should not change",
      "instance": { "foo": 3 },
      "expected": {
        "foo": 3
      }
    }
  ]
}

@dellamora
Copy link

dellamora commented Mar 11, 2023

Test that verifies an invalid property is removed from the JSON document.

 {
 "description": "This schema defines the JSON structure for a Product and a Package.",
  "schema": { 
  "anyOf": [
    { "$ref": "#/definitions/Product" },
    { "$ref": "#/definitions/Package" }
  ],
  "definitions": {
    "Product": {
      "type": "object",
      "properties": {
        "name": { "type": "string" },
        "value": { "type": "number" }
      },
      "required": ["name", "value"]
    },
    "Package": {
      "type": "object",
      "properties": {
        "name": { "type": "string" },
        "value": { "type": "number" },
        "products": {
          "type": "array",
          "items": { "$ref": "#/definitions/Product" }
        }
      },
      "required": ["name", "products"]
    }
  }
},
  "tests": [
    {
      "description": "Test that valid JSON document remains unchanged",
      "instance": {
        "name": "Product 1",
        "value": 10
      },
      "expected": {
        "name": "Product 1",
        "value": 10
      }
    },
    {
      "description": "Test that invalid property is removed from JSON document",
      "instance": {
        "name": "Product 2",
        "value": 20,
        "color": "blue"
      },
      "expected": {
        "name": "Product 2",
        "value": 20
      }
    },
    {
      "description": "Test that invalid nested property is removed from JSON document",
      "instance": {
        "name": "Package 1",
        "value": 100,
        "products": [
          {
            "name": "Product 3",
            "value": 30,
            "color": "red"
          },
          {
            "name": "Product 4",
            "value": 40
          }
        ],
        "color": "green"
      },
      "expected": {
        "name": "Package 1",
        "value": 100,
        "products": [
          {
            "name": "Product 3",
            "value": 30
          },
          {
            "name": "Product 4",
            "value": 40
          }
        ]
      }
    }

@ishaan812
Copy link

Qualifying test for transforming a url into urlParameters

For my qualification task, I've used a custom function and default for fallback values.

  • Transform: This keyword is used to call a function on it. A function will be passed in the function parameter inside the Transform. I have assumed to UrlParams to parse the url string to give out the Params and return a JSON which will then be validated by the referenced Schema definition.

I've also added a validity flag on each of the tests since I felt it was relevant to show the results properly.

{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "title": "Schema to showcase the transform property which has a subproperty of function used to determine the function being applied on the given data on the url Attribute being used to pass URL params into JSON Schema",
    "description": "I have added the custom Transform Keyword to basically run a custom function on the data given to it on the function attribute",
    "type": "object",
    "properties": {
		"url": {
			   "description": "This field uses a custom transform keyword which then parses the url given to this field transforms it using the function mentioned in the function property and also validates it using the referenced schema definition for urlParams",
			    "type": "string",
			    "transform": {
					"type": "object",
				    "$ref": "#/$defs/urlParams",
				    "function": "toUrlParams"
			    }
		}
    },
    "$defs": {
	    "urlParams": {
		    "description": "This is a subschema used to contain the URL parameters that the url will transform into",
		    "type": "object",
			"properties": {
			    "nationality": {
				    "description": "One of the url params",
					"type": "string"
			    },
				"phone": {
				    "description": "The regular expression written below parses the phone number as an Indian Phone Number",
				    "type": "string",
					"pattern": "^\\+91\\s[1-9]\\d{9}$"
				}
			},
		    "required": [
			    "phone"
			]
	    }
    },
    "tests": [
	 {
   "	description": "This test case shows how the transform keyword will create a new field with the given schema and add it to the JSON",
	    "instance": {
	    "url": "http://localhost:9000?nationality=Indian&phone=9619511390"
		 },
	    "validity": true,
	    "expected": {
		    "url": "http://localhost:9000?nationality=Indian&phone=9619511390",
			"urlParams": {
			    "nationality": "Indian",
				"phone": "9619511390"
			}
	    }
    },
    {
	    "description": "This test case shows how the pattern in the subschema after transforming will invalidate this since the given number will not pass the regular expression",
	    "instance": {
		    "url": "http://localhost:9000?nationality=Indian&phone=9819628102123"
		},
	    "validity": false,
	    "expected": {}
    },
    {
	    "description": "This test case shows how the required property in the subschema will work since nationality is not required",
	    "instance": {
		    "url": "http://localhost:9000?phone=9619511390"
	    },
	    "validity": true,
	    "expected": {
		    "url": "http://localhost:9000?phone=9619511390",
		    "urlParams": {
			    "phone": "9619511390"
		    }
	   }
    }
    ]
}

@tcskiran
Copy link

tcskiran commented Mar 12, 2023

Hello everyone. My name is Kiran, and I am a pre-final year student at IIT Kharagpur. I am a full-stack developer.

I am very interested in working on this project. I have worked mostly on backend development and used JSON schema very much, and this project is the right fit for me. JSON is essential for backend development, so any improvement is helpful to many people. I have mainly used Nodejs for most of my projects but I also interned as a Python developer. The project has so much potential like if we are trying to add new features to our project, we can add the latest properties to the schema and any default values, if any, and send all our data here to modify and similar for other cases.

I am very excited to learn new things that come along the way working with everyone.

@ankit-pn
Copy link

ankit-pn commented Mar 12, 2023

Tests for Utility 1: A Utility that takes a JSON Schema and a JSON document and adds to the document any values that are missing but have a default specified for that value in the JSON Schema.

{
    "description":"Circular Schema Representing Tree Data Structure",
    "schema":{
        "type": "object",
        "properties": {
          "node_name": { "$ref":"#/$defs/name"},
          "node_value": { "$ref": "#/$defs/value"},
          "children": {
            "type": "array",
            "items": { "$ref": "#" }
          }
        },
        "$defs":{
          "name": { "type": "string", "default": "Untitled Node"},
          "value": {"type" : "number", "default": 0}
        }
      },
      "tests": [
            {
                "description":"When schema is applied to empty object, value set to default value",
                "instance": {},
                "expected": { "node_name": "Untitled Node", "node_value": 0 }
            },
            {
                "description": "When schema is applied to object with missing value, value set to defalut value",
                "instance": {
                    "node_name": "root",
                    "node_value": 10,
                    "children": [
                      {
                        "node_name": "child 1",
                        "children": [
                          {
                            "node_name": "grandchild 1"
                          },
                          {
                            "node_value": 15
                          }
                        ]
                      },
                      {
                        "node_value": 5
                      }
                    ]
                },
                "expected": {
                    "node_name": "root",
                    "node_value": 10,
                    "children": [
                      {
                        "node_name": "child 1",
                        "children": [
                          {
                            "node_name": "grandchild 1",
                            "node_value": 0
                          },
                          {
                            "node_value": 15,
                            "node_name": "Untitled Node"
                          }
                        ],
                        "node_value": 0
                      },
                      {
                        "node_value": 5,
                        "node_name": "Untitled Node"
                      }
                    ]
                  }
            }
      ]
}

Tests for Utility 2: A Utility that takes a JSON Schema and a JSON document and removes properties in the JSON document that are not described in the JSON Schema.

 {
    "description":"Circular Schema Representing Tree Data Structure",
  
    "schema":{
    "type": "object",
    "properties": {
      "node_name": { "$ref":"#/$defs/name"},
      "node_value": { "$ref": "#/$defs/value"},
      "children": {
        "type": "array",
        "items": { "$ref": "#" }
      }
    },
    "$defs":{
      "name": { "type": "string"},
      "value": {"type" : "number"}
    }
},

    "tests":[
        {
          "description":"Test case for which object is empty",
          "instance":{},
          "expected":{}
        },
        {
        "description":"Test case of object for which properties that is defined is not present in schema",
        "instance": {
            "node_name": "root",
            "node_value": 10,
            "children": [
              {
                "node_name": "child 1",
                "children": [
                  {
                    "node_name": "grandchild 1",
                    "node_number": 10,
                    "node_value": 0
                  },
                  {
                    "node_value": 15,
                    "node_index": 6,
                    "node_name": "grandchild 2"
                  }
                ],
                "node_value": 0
              },
              {
                "node_value": 5,
                "node_name": "Untitled Node"
              }
            ]
          },
          "expected":{
            "node_name": "root",
            "node_value": 10,
            "children": [
              {
                "node_name": "child 1",
                "children": [
                  {
                    "node_name": "grandchild 1",
                    "node_value": 0
                  },
                  {
                    "node_value": 15,
                    "node_name": "grandchild 2"
                  }
                ],
                "node_value": 0
              },
              {
                "node_value": 5,
                "node_name": "Untitled Node"
              }
            ]
          }
        }
    ]
  }

Tests for Utility 3: A Utility that takes a JSON Schema and a query string from a form post (application/x-www-form-urlencoded) and convert the string to JSON using the JSON Schema to know the types for the values.

{
    "tests":[
        {
            "description":"When Schema is applied to empty string",
            "schema":"",
            "instance":"",
            "expected":""
        },
        {
            "description":"When Schema is applied to string that matches schema",
            "schema":{
                "description": "Schema Representing Foo Object",
                "type": "object",
                "properties": {
                  "foo": {"type": "string"},
                  "num": {"type": "number"},
                  "user": {
                    "type": "object",
                    "required": ["name", "age"],
                    "properties": {
                      "name": {"type": "string"},
                      "age": {"type": "number"}
                    }
                  },
                  "address": {
                    "type": "object",
                    "required": ["city", "state", "zip"],
                    "properties": {
                      "city": {"type": "string"},
                      "state": {"type": "string"},
                      "zip": {"type": "string", "pattern": "^[0-9]{5}$"}
                    }
                  },
                  "colors": {"type": "string"},
                  "options": {
                    "type": "array",
                    "minItems": 1,
                    "items": {
                      "type": "object",
                      "required": ["value", "label"],
                      "properties": {
                        "value": {"type": "string"},
                        "label": {"type": "string"}
                      }
                    }
                  }
                }
              },
            "instance":"?foo=bar&num[]=1&num[]=2&user[name]=John+Doe&user[age]=30&address[city]=New+York&address[state]=NY&address[zip]=10001&colors[]=red&colors[]=blue&colors[]=green&options[0][value]=option1&options[0][label]=Option+1&options[1][value]=option2&options[1][label]=Option+2&options[2][value]=option3&options[2][label]=Option+3",
            "expected": {
                "foo": "bar",
                "num": 2,
                "user": {
                  "name": "John Doe",
                  "age": 30
                },
                "address": {
                  "city": "New York",
                  "state": "NY",
                  "zip": "10001"
                },
                "colors": "green",
                "options": [
                  {
                    "value": "option1",
                    "label": "Option 1"
                  },
                  {
                    "value": "option2",
                    "label": "Option 2"
                  },
                  {
                    "value": "option3",
                    "label": "Option 3"
                  }
                ]
              }
        }
      ]
}

@tcskiran
Copy link

tcskiran commented Mar 12, 2023

Here is my submission for the qualifying task
Adding default values to JSON document

{
  "description": "Testing the conditional application of defaults using dependentSchemas",
  "schema": {
    "type": "object",
    "properties": {
      "name": {
        "type": "string"
      },
      "email": {
        "type": "string"
      },
      "age": {
        "type": "number"
      }
    },
    "dependentSchemas": {
      "email": {
        "properties": {
          "age": {
            "default": 21
          }
        }
      },
      "name": {
        "properties": {
          "age": {
            "default": 25
          }
        }
      }
    }
  },
  "tests": [
    {
      "description": "No changes are made if an empty object is given as there are no dependent schemas",
      "instance": {},
      "expected": {}
    },
    {
      "description": "If only email is given, dependency for email is applied",
      "instance": {
        "email": "test@gmail.com"
      },
      "expected": {
        "email": "test@gmail.com",
        "age": 21
      }
    },
    {
      "description": "If only name is given, dependency for a name is applied",
      "instance": {
        "name": "John Doe"
      },
      "expected": {
        "name": "John Doe",
        "age": 25
      }
    },
    {
      "description": "If age is given, no changes are made as there are no dependencies",
      "instance": {
        "age": 30
      },
      "expected": {
        "age": 30
      }
    },
    {
      "description": "If age is given and other values are also given, no changes are made as age already has a value(default does not apply if value is present)",
      "instance": {
        "email": "test@gmail.com",
        "name": "John Doe",
        "age": 30
      },
      "expected": {
        "email": "test@gmail.com",
        "name": "John Doe",
        "age": 30
      }
    },
    {
      "description": "If both name and email are given and age is not given, then there are 2 possibilities",
      "instance": {
        "email": "test@gmail.com",
        "name": "John Doe",
      },
      "expected": [
        {
          "email": "test@gmail.com",
          "name": "John Doe",
          "age": 21
        },
        {
          "email": "test@gmail.com",
          "name": "John Doe",
          "age": 25
        }
      ]
    }
  ]
}

@Atish03
Copy link

Atish03 commented Mar 13, 2023

Resubmission for Qualification Task

{
	"description": "trading cypto in INR and USD",
	"$defs": {
		"transac_request": {
			"type": "object",
			"properties": {
				"from": {
					"type": "string",
					"enum": [ "BTC", "ETH", "BCH", "MANA", "BAT" ]
				},
				"to": {
					"type": "string",
					"enum": [ "USD", "INR" ]
				}
			}
		},
		"to_inr": {
			"properties": {
				"request": {
					"to": {
						"const": "INR"
					}
				}
			}
		},
		"to_usd": {
			"properties": {
				"request": {
					"to": {
						"const": "USD"
					}
				}
			}
		}
	},
	"schema": {
		"description": "applies taxation conditionally if transaction is from Any to INR or from BAT to USD, tax is 5% else 10%",
		"type": "object",
		"properties": {
			"request": {
				"$ref": "#/$defs/transac_request"
			},
			"amount": {
				"type": "number",
				"default": 0.0
			}
		},
		"if": {
			"anyOf": [
				{ "$ref": "#/$defs/to_inr" },
				{ "allOf": [
					{ "$ref": "#/$defs/to_usd" },
					{
						"properties": {
							"request": {
								"from": "BAT"
							}
						}
					}
				]
				}
			]
		},
		"then": {
			"properties": {
				"tax": {
					"const": "5%"
				}
			}
		},
		"else": {
			"properties": {
				"tax": {
					"const": "10%"
				}
			}
		}
	},

	"tests": [
		{
			"description": "transaction from BAT to USD",
			"instance": {
				"from": "BAT",
				"to": "USD",
				"amount": 100.0
			},
			"expected": {
				"from": "BAT",
				"to": "USD",
				"amount": 100.0,
				"tax": "5%"
			}
		},
		{
			"description": "transaction from any except BAT to USD",
			"instance": {
				"from": "BTC",
				"to": "USD",
				"amount": 100.0
			},
			"expected": {
				"from": "BTC",
				"to": "USD",
				"amount": 100.0,
				"tax": "10%"
			}
		},
		{
			"description": "transaction from Any to INR",
			"instance": {
				"from": "MANA",
				"to": "INR",
				"amount": 100.0
			},
			"expected": {
				"from": "MANA",
				"to": "INR",
				"amount": 100.0,
				"tax": "5%"
			}
		}
	]
}

@Atish03
Copy link

Atish03 commented Mar 14, 2023

Submission for Qualifination Task

{
	"description": "A schema which defaults the color of planets conditionally",
	"schema": {
		"type": "object",
		"properties": {
			"data": {
				"type": "object",
                                "properties: {
				          "name": {
					          "type": "string",
					          "default": "Mars"
				          },
				          "color": {
					          "type": "string"
				          }
                                 }               
			}       
		},
		"allOf": [
			{ "if": {
				"properties": { "data": { "name": { "const": "Earth" } } }
			},
			"then": {
				"properties": { "data": { "color": { "default": "blue" } } }
			},
			"else": {
				"properties": { "data": { "color": { "default": "green" } } }
			}},
			{ "if": {
				"properties": { "data": { "name": { "const": "Mars" } } }
			},
			"then": {
				"properties": { "data": { "color": { "default": "red" } } }
			}},
			{ "if": {
				"properties": { "data": { "name": { "const": "Earth" }, "not": { "color": { "const": "blue" } } } }
			},
			"then": {
				"properties": { "data": { "color": { "const": "blue" } } }
			}}
		]
	},
	"tests": [
		{
			"description": "passing an empty instance, the name defaults to 'Mars' and the color defaults to 'red'",
			"instance": {},
			"expected": {
				"name": "Mars",
				"color": "red"
			}
		},
		{
			"description": "passing 'Earth' as the name, the color defaults to blue if no color is specified",
			"instance": {
				"name": "Earth",
			},
			"expected": {
				"name": "Earth",
				"color": "blue"
			}
		},
		{
			"description": "passing 'Earth' as the name, and any value for color, the color changes to blue",
			"instance": {
				"name": "Earth",
				"color": "orange"
			},
			"expected": {
				"name": "Earth",
				"color": "blue"
			}
		}
	]
}

@abhayra12
Copy link

hello, what about this
submission for qualification task

{ "schema": { "type": "object", "properties": { "name": { "type": "string", "default": "John Doe" }, "age": { "type": "integer", "default": 25 }, "hobbies": { "type": "array", "default": ["reading", "hiking"] } }, "required": ["name"] }, "doc": { "name": "Jane Doe", "age": 30 }, "expected_output": { "name": "Jane Doe", "age": 30, "hobbies": ["reading", "hiking"] } }

@jdesrosiers
Copy link
Collaborator

@abhay-ahirkar, have you joined our Slack (#gsoc-2023) yet? Ping me there, and I can give you feedback there.

@MPrashanthR
Copy link

Hi everyone. Thanks again for your interest in this project. In the contributor guidance document, it mentions picking up a "first issue" task for the project and "mandatory qualification task". However, that only makes sense for contributing to an existing project and this project will be built from scratch. Creating a repo and setting it up for development, testing, publishing, and contributions will all be a part of your responsibilities. So, I came up with a qualification task that we can do without a repo or any code.

Qualification Task

Provide a test case that can be used as an acceptance test for any of the transformation operations described in the project description. This test should be expressed in JSON and include the inputs and expected output for the transformation operation. You can post your tests in this thread. Look over the tests others have posted before you and make sure someone hasn't already posted something testing the same thing. You can show that you understand the complexities you'll face with this project by coming up with a non-trivial test case.

Example for applying defaults

{
  "description": "Given a schema with a default set for the 'foo' property",
  "schema": {
    "type": "object",
    "properties": {
      "foo": {
        "type": "number",
        "default": 42
    }
  },
  "tests": [
    {
      "description": "When the schema is applied to an empty object, the 'foo' property should be set to the default value",
      "instance": {},
      "expected": {
        "foo": 42
      }
    },
    {
      "description": "When the schema is applied to an object where 'foo' exists, the 'foo' property should not change",
      "instance": { "foo": 3 },
      "expected": {
        "foo": 3
      }
    }
  ]
}

And ### submission for qualification task

Hi! I can definitely help you with the qualification task. Here's my test case for the "rename" transformation operation:

{
"description": "Given a schema with a property 'old_name', rename it to 'new_name'",
"schema": {
"type": "object",
"properties": {
"old_name": {
"type": "string"
}
},
"transformation": {
"rename": {
"old_name": "new_name"
}
}
},
"tests": [
{
"description": "When the schema is applied to an object with the 'old_name' property, it should be renamed to 'new_name'",
"instance": {
"old_name": "Hello World"
},
"expected": {
"new_name": "Hello World"
}
},
{
"description": "When the schema is applied to an object without the 'old_name' property, the object should remain unchanged",
"instance": {
"other_property": 123
},
"expected": {
"other_property": 123
}
},
{
"description": "When the schema is applied to an object with both 'old_name' and 'new_name' properties, 'old_name' should be renamed to 'new_name' and the original 'new_name' property should be removed",
"instance": {
"old_name": "Hello World",
"new_name": "Goodbye World"
},
"expected": {
"new_name": "Hello World"
}
}
]
}

I hope this test case demonstrates my understanding of the complexities involved in creating non-trivial test cases. Let me know if you have any questions or need further clarification.

@ishaan812
Copy link

ishaan812 commented Mar 17, 2023

Utility to run defaults on nested Arrays

{
    "description": "Nested Arrays with defaults",
    "schema": {
	    "type": "object",
	    "properties": {
		    "arr": {
			    "type": "array",
			    "items": {
				    "type": "array",
				    "items": {
					    "type": "number",
					    "default": 0
					 },
					 "default": [1,2,3]
				},
				"default": [
					[4,5,6],
					[7,8,9]
				]
			}
		}
	}
	"tests": [
		{
			"description": "This test case shows the top level default running",
			"instance": {},
			"expected": {
				"arr": [[4,5,6],[7,8,9]]
			}
		},
		{
			"description": "This test case shows the middle level default running",
			"instance": {
				"arr": []
			},
			"expected": {
				"arr": [[1,2,3]]
			}
		},
		{
			"description": "This test case shows the bottom level default running",
			"instance": {
				"arr": [[]]
			},
			"expected": {
				"arr": [[0]]
			}
		}
	]
}

@kart1ka
Copy link

kart1ka commented Mar 18, 2023

Re-submission for qualifying task:

{
	"description": "An array with first two items as objects and rest as strings",
	"schema": {
		"type": "array",
		"prefixItems": [
			{
				"type": "object",
				"properties": {
					"key1": {
						"type": "string",
						"default": "value1"
					},
				},
			},
			{
				"type": "object",
				"properties": {
					"key2": {
						"type": "number",
						"default": 0
					},
				},
			},
		],
		"items": {
			"type": "string",
		}
	},
	"tests": [
		{
			"description": "When an empty object is passed as first item in array, default value corresponding to key1 kicks in.",
			"instance": [{}, { "key2": 10 }, "str"],
			"expected": [{ "key1": "value1" }, { "key2": 10 }, "str"],
		},
		{
			"description": "When an empty object is passed as the second item in array, default value corresponding to key2 kicks in.",
			"instance": [{ "key1": "val" }, {}, "str"],
			"expected": [{ "key1": "val" }, { "key2": 0 }, "str"],
		},
	],
}

@benjagm
Copy link
Collaborator Author

benjagm commented Mar 21, 2023

Thanks a lot for your hard work with your messages and qualifying tasks! We are looking forward to receive your applications. Please ask us for feedback with your applications anytime, we'd love to help.

Please, join the JSON Schema Slack server using this link and join channel #gsoc-2023 to stay up to date with all the communications and announcements.

@affaannn
Copy link

affaannn commented Apr 9, 2023

{
   "description": "Given a JSON Schema and a JSON document for book object, that removes properties in the JSON document  that are not described as per the JSON Schema.",

  "schema": {
  "type": "object",
  "properties": {
    "title": { "type": "string" },
    "author": { "type": "string" },
    "year": { "type": "integer" },
    "price": { "type": "number" },
    "genre": { "type": "string" }
  },
  "anyOf": [
    {
      "properties": {
        "title": { "pattern": "^[A-Za-z0-9\\- ]+$" },
        "author": { "pattern": "^[A-Za-z\\- ]+$" },
        "year": { "minimum": 0, "maximum": 2023 },
        "price": { "minimum": 0 },
        "genre": {
          "enum": [
            "Fiction",
            "Mystery",
            "Thriller",
            "Romance",
            "Science Fiction",
            "Fantasy",
            "Horror",
            "Historical Fiction"
          ]
        }
      },
     "required": ["title", "author", "year", "price", "genre"]
    },
    {
      "properties": {
        "title": { "type": "string", "minLength": 1 },
        "author": { "type": "string", "minLength": 1 },
        "year": { "type": "integer", "minimum": 0, "maximum": 2023 },
        "genre": {
          "enum": [
            "Fiction",
            "Mystery",
            "Thriller",
            "Romance",
            "Science Fiction",
            "Fantasy",
            "Horror",
            "Historical Fiction"
          ]
        }
      },

      "required": ["title", "author", "year", "genre"]
    },
    {
     
      "properties": {
        "title": { "type": "string", "minLength": 1 },
        "author": { "type": "string", "minLength": 1 },
        "price": { "type": "number", "minimum": 0 }
      },
       "required": ["title", "author", "price"]
    }
  ]
},
  "tests": [
      {
        "description": "schema is applied to an empty object, it will just return the empty object",
        "document": {},
        "expected_result": {}
      },
       {
        "description": "schema is applied to valid inputs for book with all properties:",
        "document": {
                            "title": "Harry Potter and the Philosopher's Stone",
                             "author": "J.K. Rowling",
                             "year": 1997,
                             "price": 12.99,
                             "genre": "Fantasy"
                            },
        "expected_result": {
                            "title": "Harry Potter and the Philosopher's Stone",
                             "author": "J.K. Rowling",
                             "year": 1997,
                             "price": 12.99,
                             "genre": "Fantasy"
                            }

      },
       {
        "description": "schema is applied to an object with additional property, it will just remove that undefind property from the 
                                  object",
        "document": {
                            "title": "Harry Potter and the Philosopher's Stone",
                             "author": "J.K. Rowling",
                             "year": 1997,
                             "price": 12.99,
                             "genre": "Fantasy",
                             "publisher": "Bloomsbury Publishing"
                            },,
        "expected_result": {
                            "title": "Harry Potter and the Philosopher's Stone",
                             "author": "J.K. Rowling",
                             "year": 1997,
                             "price": 12.99,
                             "genre": "Fantasy"
                            }
      },
      {
        "description": "schema is applied to the object with an extra property which is not in combination, it will just remove that 
                                property",
        "document": {
                             "title": "Harry Potter and the Philosopher's Stone",
                             "author": "J.K. Rowling",
                             "year": 1997,
                             "price": 12.99
                              },
        "expected_result":  {
                             "title": "Harry Potter and the Philosopher's Stone",
                             "author": "J.K. Rowling"
                             "price": 12.99
                              }
      }
  ]
}      

@benjagm
Copy link
Collaborator Author

benjagm commented Feb 20, 2024

Closed as completed as part of 2023 edition.

@benjagm benjagm closed this as completed Feb 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests