#C13040. User Data Validator
User Data Validator
User Data Validator
You are given a JSON array of users via standard input. Each user is represented as a JSON object containing three keys: id
, name
, and email
. Your task is to validate this list and separate it into two lists:
- Valid Users: Users whose email addresses contain the '@' character.
- Users with Invalid Emails: Users whose email addresses do not contain the '@' character.
If any user object is missing one of the required fields, immediately output an error message with the following format:
Missing field in user data: <field>
and terminate the program.
If all user objects contain the required fields, output the results in two sections. The first section begins with the line "Valid Users:" followed by the JSON array of valid users. After a blank line, the second section should have the line "Users with Invalid Emails:" followed by the JSON array of invalid users.
Note: All outputs must be printed to standard output.
inputFormat
A single line from standard input containing a JSON array of user objects. Each user object has the following format:
{"id": <number>, "name": <string>, "email": <string>}
There are no extra spaces or line breaks within the JSON objects.
outputFormat
If any user object is missing a required field, output a single line with the error message:
Missing field in user data: <missing_field>
Otherwise, output exactly the following format:
Valid Users:
<JSON array of valid users>
Users with Invalid Emails:
<JSON array of invalid users>
Make sure to print to standard output (stdout).## sample
[{"id": 1, "name": "John Doe", "email": "john.doe@example.com"}, {"id": 2, "name": "Jane Smith", "email": "jane.smith@example.com"}]
Valid Users:
[{"id": 1, "name": "John Doe", "email": "john.doe@example.com"}, {"id": 2, "name": "Jane Smith", "email": "jane.smith@example.com"}]
Users with Invalid Emails:
[]
</p>