instruction_seed
stringlengths
217
5.42k
response_seed
stringlengths
16
128k
response
stringlengths
10
14.5k
__original_row_idx
int64
0
35.9k
conversations
listlengths
2
2
Design a JSON schema for a class representation in a software application. The schema should define a class with the following attributes: - `name`: The name of the class (required, string) - `super`: The superclass from which the class inherits (optional, string) - `category`: The category to which the class belong...
```python import json from jsonschema import validate from jsonschema.exceptions import ValidationError # Define the JSON schema for the class representation class_schema = { "type": "object", "properties": { "name": {"type": "string"}, "super": {"type": "string"}, "category": {"type"...
Here's the JSON schema based on your requirements, followed by a Python function that validates a given JSON string against that schema using the `jsonschema` library. ### JSON Schema ```json { "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "properties": { "name": { "type": "s...
10,300
[ { "from": "human", "value": "\n\nDesign a JSON schema for a class representation in a software application. The schema should define a class with the following attributes:\n\n- `name`: The name of the class (required, string)\n- `super`: The superclass from which the class inherits (optional, string)\n- `ca...
Write a Python function `parse_cve_details` that takes a JSON string representing a Common Vulnerabilities and Exposures (CVE) entry and returns a dictionary with specific details about the CVE. The function should extract the following information: - CVE ID - Description - Severity (from baseMetricV3) - List of vul...
```python import json def parse_cve_details(cve_json: str) -> dict: cve_data = json.loads(cve_json) cve_details = { 'cve_id': cve_data['cve']['CVE_data_meta']['ID'], 'description': cve_data['cve']['description']['description_data'][0]['value'], 'severity': cve_data['impact']['baseMetr...
Below is the implementation of the `parse_cve_details` function as per your requirements. This function will take a JSON string, parse it, and extract specific details about the CVE, including the CVE ID, description, severity, list of vulnerable product versions, and a list of references (URLs). Ensure that you have ...
10,301
[ { "from": "human", "value": "\n\nWrite a Python function `parse_cve_details` that takes a JSON string representing a Common Vulnerabilities and Exposures (CVE) entry and returns a dictionary with specific details about the CVE. The function should extract the following information:\n\n- CVE ID\n- Descriptio...
You are given a JSON object representing the configuration of a mobile application project. The JSON object contains information about the project, client details, OAuth clients, API keys, and services. Your task is to write a Python function `extract_client_package_name(json_data)` that takes this JSON object as inp...
```python import json def extract_client_package_name(json_data): """ Extracts the package name of the Android client from the given JSON data. :param json_data: A string containing the JSON object with project configuration. :return: The package name if found, otherwise None. """ try: ...
To achieve the functionality you've described, we will create a Python function `extract_client_package_name` that will handle the JSON parsing and package name extraction. The function will include error handling to manage any issues that might arise during the parsing process. Here's the implementation: ```python ...
10,302
[ { "from": "human", "value": "\n\nYou are given a JSON object representing the configuration of a mobile application project. The JSON object contains information about the project, client details, OAuth clients, API keys, and services. Your task is to write a Python function `extract_client_package_name(jso...
Create a Python function named `parse_bus_predictions` that takes a JSON string representing bus stop information, including predicted arrival times for buses, and returns a list of dictionaries with the following keys for each bus service that is currently operating (i.e., `codigorespuesta` is "00"): - `service`: T...
```python import json def parse_bus_predictions(json_data): """ Parses a JSON string containing bus stop information and returns a list of dictionaries with predicted arrival times and distances for buses that are currently operating. :param json_data: A JSON string containing bus stop informati...
To create the `parse_bus_predictions` function, we will first import the necessary library for handling JSON data. We'll then parse the input JSON string and filter the bus services based on the specified conditions. Here is the implementation of the function: ```python import json def parse_bus_predictions(json_st...
10,303
[ { "from": "human", "value": "\n\nCreate a Python function named `parse_bus_predictions` that takes a JSON string representing bus stop information, including predicted arrival times for buses, and returns a list of dictionaries with the following keys for each bus service that is currently operating (i.e., ...
You are given a JSON object representing a collection of log entries. Each log entry contains an `outputFile` path and a `map` list. Each item in the `map` list contains a `source` file path and a `from` object with details about the location in the source file (`startLines`, `startColumns`, `startOffsets`, `endColum...
```python import json def summarize_log_locations(logs_json): """ Summarizes the locations from the source files in the given logs JSON object. :param logs_json: A JSON object containing log entries with source file locations. :return: A dictionary with source file paths as keys and lists of (st...
Here's a Python function `summarize_log_locations(logs_json)` that takes a JSON object as input and returns a summary of the locations from the source files as specified. ```python import json def summarize_log_locations(logs_json): summary = {} for entry in logs_json['logs']: for mapping in entr...
10,304
[ { "from": "human", "value": "\n\nYou are given a JSON object representing a collection of log entries. Each log entry contains an `outputFile` path and a `map` list. Each item in the `map` list contains a `source` file path and a `from` object with details about the location in the source file (`startLines`...
Design a Python function `calculate_royalty_fee` that computes the royalty fee for a given sale price of an NFT (Non-Fungible Token) based on the provided JSON metadata. The function should parse the JSON metadata to extract the `seller_fee_basis_points` and calculate the royalty fee that the seller would receive fro...
```python import json def calculate_royalty_fee(metadata_json, sale_price): """ Calculate the royalty fee for a given sale price of an NFT based on the provided JSON metadata. :param metadata_json: A string containing the JSON metadata of the NFT. :param sale_price: A float representing the sale...
Sure! Below is a Python function `calculate_royalty_fee` that meets the specified requirements. The function will parse a JSON string to extract the `seller_fee_basis_points`, compute the royalty fee based on the provided `sale_price`, and include error handling for various cases. ```python import json def calculate_...
10,305
[ { "from": "human", "value": "\n\nDesign a Python function `calculate_royalty_fee` that computes the royalty fee for a given sale price of an NFT (Non-Fungible Token) based on the provided JSON metadata. The function should parse the JSON metadata to extract the `seller_fee_basis_points` and calculate the ro...
Design a Python function `parse_game_save_data` that takes a JSON string representing a game save file and extracts specific information about the player's game state. The function should return a dictionary with the following keys and their corresponding values from the JSON data: - `gameDefinition` - `activeQuests...
```python import json def parse_game_save_data(json_data): """ Parses a JSON string representing a game save file and extracts specific information. Parameters: - json_data (str): A JSON string representing the game save data. Returns: - dict: A dictionary with extracted player game...
To implement the `parse_game_save_data` function, we will use the `json` module to parse the json string into a Python dictionary. After that, we will extract the required keys, ensuring that if a key does not exist in the JSON data, we assign `None` to that key in the output dictionary. Here’s how the function can be...
10,306
[ { "from": "human", "value": "\n\nDesign a Python function `parse_game_save_data` that takes a JSON string representing a game save file and extracts specific information about the player's game state. The function should return a dictionary with the following keys and their corresponding values from the JSO...
Write a Python function `update_package_json` that takes a JSON string representing a `package.json` file (commonly used in JavaScript and Node.js projects) and updates it according to the following rules: 1. Increment the minor version of the `version` field by 1. For example, if the version is "1.0.0", it should b...
```python import json from packaging import version def update_package_json(json_str): """ Updates the package.json content according to the specified rules. Parameters: - json_str: A string containing the JSON content of package.json. Returns: - A string containing the updated JSON content...
To implement the `update_package_json` function in Python, we will follow the specified rules to modify the `package.json` content represented as a JSON string. We'll use the `json` module for parsing and formatting the JSON data. Here's how you can do it: ```python import json import re def update_minor_version(vers...
10,307
[ { "from": "human", "value": "\n\nWrite a Python function `update_package_json` that takes a JSON string representing a `package.json` file (commonly used in JavaScript and Node.js projects) and updates it according to the following rules:\n\n1. Increment the minor version of the `version` field by 1. For ex...
Write a Python function `validate_flatpak_manifest` that takes a JSON string representing a Flatpak application manifest and validates it according to the following rules: 1. The manifest must be a valid JSON object. 2. The manifest must contain the following top-level keys: `app-id`, `runtime`, `runtime-version`, `...
```python import json def validate_flatpak_manifest(json_string): """ Validates a Flatpak application manifest JSON string. Args: - json_string (str): The JSON string of the manifest. Returns: - bool: True if the manifest is valid, otherwise raises ValueError. Raises: - ValueError:...
To create the `validate_flatpak_manifest` function that follows the specified validation rules for a Flatpak application manifest in JSON format, we can implement the function step by step. Here's how you can do it in Python: ```python import json def validate_flatpak_manifest(json_string): try: # Step 1:...
10,308
[ { "from": "human", "value": "\n\nWrite a Python function `validate_flatpak_manifest` that takes a JSON string representing a Flatpak application manifest and validates it according to the following rules:\n\n1. The manifest must be a valid JSON object.\n2. The manifest must contain the following top-level k...
Write a Python function `update_dependencies` that takes a JSON string representing a package configuration (similar to the one provided in the given code snippet) and a dictionary of dependencies with their new versions. The function should update the versions of the dependencies in the JSON string with the new versi...
```python import json def update_dependencies(json_string: str, new_versions: dict) -> str: """ Updates the versions of dependencies in a JSON string with the new versions provided. :param json_string: A JSON string representing a package configuration. :param new_versions: A dictionary with package ...
To implement the `update_dependencies` function, we will follow these steps: 1. Parse the provided JSON string into a Python dictionary using the `json` module. 2. Update the dependencies in the dictionary with the new versions from the provided dictionary, if they exist in the parsed dictionary. 3. Convert the update...
10,309
[ { "from": "human", "value": "\nWrite a Python function `update_dependencies` that takes a JSON string representing a package configuration (similar to the one provided in the given code snippet) and a dictionary of dependencies with their new versions. The function should update the versions of the dependen...
Write a Python function `validate_software_manifest` that takes a JSON string representing a software manifest and validates it against the following rules: 1. The `token` must be a non-empty string. 2. The `name` must be a list containing at least one non-empty string. 3. The `desc` (description) must be a non-empt...
```python import json from urllib.parse import urlparse def is_valid_url(url): try: result = urlparse(url) return all([result.scheme, result.netloc]) except ValueError: return False def validate_software_manifest(json_string): """ Validates a software manifest JSON string aga...
To implement the `validate_software_manifest` function to validate a software manifest based on the specified rules, we can break down the requirements and check each condition. We will also use the `json` library to parse the JSON string and validate URLs using a regular expression. Here's the complete implementation...
10,310
[ { "from": "human", "value": "\n\nWrite a Python function `validate_software_manifest` that takes a JSON string representing a software manifest and validates it against the following rules:\n\n1. The `token` must be a non-empty string.\n2. The `name` must be a list containing at least one non-empty string.\...
You are tasked with creating a Python function that takes a JSON string representing an NFT (Non-Fungible Token) metadata and returns a dictionary with specific details about the NFT. The function should extract the following information from the JSON: - `name`: The name of the NFT. - `image_url`: The URL of the NFT...
```python import json def extract_nft_details(json_string: str) -> dict: """ Extracts details from a JSON string representing an NFT metadata. Parameters: - json_string (str): A JSON string representing the NFT metadata. Returns: - dict: A dictionary containing the 'name', 'image_url', and ...
Certainly! Below is the implementation of the `extract_nft_details` function that meets your requirements. This function takes a JSON string, parses it, and extracts the name, image URL, and attributes of the NFT. ```python import json def extract_nft_details(json_string: str) -> dict: """ Extracts details fr...
10,311
[ { "from": "human", "value": "\n\nYou are tasked with creating a Python function that takes a JSON string representing an NFT (Non-Fungible Token) metadata and returns a dictionary with specific details about the NFT. The function should extract the following information from the JSON:\n\n- `name`: The name ...
You are given a list of comments from a GitHub issue in JSON format. Each comment contains information about the author, the content of the comment, timestamps, and other metadata. Your task is to write a Python function `summarize_comments` that takes this JSON data as input and returns a summary of the comments. Th...
```python import json def summarize_comments(comments_json: str) -> dict: comments = json.loads(comments_json) unique_authors = set() for comment in comments: unique_authors.add(comment['user']['login']) summary = { 'total_comments': len(comments), 'unique_authors': len(unique...
You can use the following Python function to summarize the comments from a GitHub issue in the specified JSON format. Here's how you can implement the `summarize_comments` function: ```python import json def summarize_comments(comments_json: str) -> dict: """ Summarizes the comments from a GitHub issue provid...
10,312
[ { "from": "human", "value": "\n\nYou are given a list of comments from a GitHub issue in JSON format. Each comment contains information about the author, the content of the comment, timestamps, and other metadata. Your task is to write a Python function `summarize_comments` that takes this JSON data as inpu...
Write a Python function `update_package_versions` that takes a JSON string representing a project's package.json file and a dictionary of package updates. The function should update the versions of the specified packages in both `dependencies` and `devDependencies` to the versions provided in the updates dictionary. ...
```python import json def update_package_versions(package_json, updates): """ Updates the versions of specified packages in both dependencies and devDependencies in a package.json file represented as a JSON string. :param package_json: A JSON string representing a package.json file. :param updat...
To create the `update_package_versions` function according to the provided specifications, we can follow these steps: 1. Parse the JSON string into a Python dictionary. 2. Update the versions of the packages specified in the updates dictionary, if they exist in `dependencies` or `devDependencies`. 3. Convert the updat...
10,313
[ { "from": "human", "value": "\n\nWrite a Python function `update_package_versions` that takes a JSON string representing a project's package.json file and a dictionary of package updates. The function should update the versions of the specified packages in both `dependencies` and `devDependencies` to the ve...
You are tasked with creating a function `filter_items_by_prefix` that takes a JSON object containing a list of item strings and a prefix string. The function should return a new JSON object with the list filtered to only include items that start with the given prefix. The JSON object will have the following structur...
```python import json def filter_items_by_prefix(json_data: str, prefix: str) -> str: """ Filters the items in the JSON data by the given prefix. :param json_data: A JSON string containing a list of item strings under the key "values". :param prefix: A string prefix to filter the item strings by. ...
To create the `filter_items_by_prefix` function as specified, we will use the `json` library in Python to work with the JSON data. Below is the implementation of the function according to your requirements: ```python import json def filter_items_by_prefix(json_data: str, prefix: str) -> str: """ Filters the i...
10,314
[ { "from": "human", "value": "\n\nYou are tasked with creating a function `filter_items_by_prefix` that takes a JSON object containing a list of item strings and a prefix string. The function should return a new JSON object with the list filtered to only include items that start with the given prefix.\n\nThe...
Write a function `apply_patch` that takes a JSON object representing a code snippet and a patch to be applied to it. The JSON object contains the following keys: - `exact_match`: A boolean indicating if the patch should be applied only if there is an exact match of the `source` string in the code. - `correct`: A boo...
```python import json def apply_patch(code_snippet): """ Applies a patch to a given code snippet if the patch is plausible and correct. Parameters: code_snippet (dict): A JSON object containing the code snippet and patch information. Returns: str: The modified code if the patch is a...
Certainly! Below is the implementation of the `apply_patch` function according to your specifications: ```python def apply_patch(code_snippet, code): """ Applies a patch to a given code snippet based on the provided conditions. Parameters: code_snippet (dict): A JSON-like dict representing the pat...
10,315
[ { "from": "human", "value": "\n\nWrite a function `apply_patch` that takes a JSON object representing a code snippet and a patch to be applied to it. The JSON object contains the following keys:\n\n- `exact_match`: A boolean indicating if the patch should be applied only if there is an exact match of the `s...
Write a Python function `update_package_json` that takes a JSON string representing a package configuration (similar to the one provided in the given code snippet) and a dictionary of updates. The function should apply the updates to the JSON string and return the updated JSON string. The updates dictionary will have...
```python import json def update_package_json(json_str, updates): """ Updates the package configuration JSON string with the provided updates. Parameters: - json_str (str): A JSON string representing a package configuration. - updates (dict): A dictionary containing updates to be applied to the ...
To implement the `update_package_json` function as you've described, we'll first need to parse the JSON string into a Python dictionary. After applying the updates while respecting the rules provided, we'll convert the dictionary back into a JSON string and return it. Here's a complete implementation of the `update_pa...
10,316
[ { "from": "human", "value": "\n\nWrite a Python function `update_package_json` that takes a JSON string representing a package configuration (similar to the one provided in the given code snippet) and a dictionary of updates. The function should apply the updates to the JSON string and return the updated JS...
Write a Python script that reads a JSON file containing a package configuration (similar to the given code snippet, which represents a `package.json` file from a Node.js project) and performs the following tasks: 1. Extracts the name and version of the package. 2. Lists all the scripts available under the "scripts" s...
```python import json import re from urllib.parse import urlparse # Importing required packages import json import re from urllib.parse import urlparse def validate_git_url(url): """Validate if the provided URL is a valid git repository URL.""" regex = re.compile( r'^(?:ssh|git|http(?:s)?)://' # htt...
Certainly! Below is a Python script that performs the tasks you described. The script reads a `package.json` file, extracts relevant information, and handles missing fields gracefully. Make sure to have the `json` module available (it's in the standard library, so no extra installations are needed). ```python import ...
10,317
[ { "from": "human", "value": "\nWrite a Python script that reads a JSON file containing a package configuration (similar to the given code snippet, which represents a `package.json` file from a Node.js project) and performs the following tasks:\n\n1. Extracts the name and version of the package.\n2. Lists al...
Given a JSON document representing a text split into sentences and tokens, write a Python function `extract_entities` that extracts named entities from the text. A named entity is defined as a sequence of tokens that start with a capital letter and are consecutive in the text. The function should return a list of nam...
```python import json def extract_entities(document): """ Extracts named entities from the given document. :param document: A JSON document containing sentences and tokens. :return: A list of named entities. """ entities = [] current_entity = [] for sentence in document['sentenc...
To extract named entities from the specified JSON structure, we need to inspect the tokens in each sentence, identify sequences of tokens that start with a capital letter, and group them together into named entities. Here’s how you can implement the `extract_entities` function in Python: ```python import json def ext...
10,318
[ { "from": "human", "value": "\n\nGiven a JSON document representing a text split into sentences and tokens, write a Python function `extract_entities` that extracts named entities from the text. A named entity is defined as a sequence of tokens that start with a capital letter and are consecutive in the tex...
In the game of Minecraft, players can craft new items by combining other items according to specific recipes. Write a Python function `craft_item(recipe, inventory)` that takes a JSON object `recipe` representing a shapeless crafting recipe and a dictionary `inventory` representing the player's current inventory. The...
```python import json def craft_item(recipe, inventory): """ Crafts an item based on a given recipe and updates the player's inventory. :param recipe: JSON object representing the crafting recipe :param inventory: dict representing the player's current inventory :return: dict representing the up...
Here's a Python function `craft_item` that implements the described functionality for crafting in Minecraft based on a JSON object recipe and the player's inventory. The function checks if the player has all the required ingredients, updates the inventory if crafting is possible, and returns the new inventory. ```pyth...
10,319
[ { "from": "human", "value": "\n\nIn the game of Minecraft, players can craft new items by combining other items according to specific recipes. Write a Python function `craft_item(recipe, inventory)` that takes a JSON object `recipe` representing a shapeless crafting recipe and a dictionary `inventory` repre...
You are tasked with writing a Python function `find_max_books_path` that takes a hierarchical structure of a company's employees and the number of books each employee is donating, and returns the path through the hierarchy that results in the maximum number of books collected. The hierarchy is represented as a CEO who...
```python import json def find_max_books_path(company_structure): """ Finds the path through the company hierarchy that results in the maximum number of books collected. :param company_structure: A dictionary representing the company's hierarchy and the number of books donated by each employee. :...
Certainly! Below, I provide a Python function `find_max_books_path`. This function takes the hierarchical input structure as described and calculates the path through the hierarchy that results in the maximum number of books collected. The function iterates through the structure, computes the total books donated for ea...
10,320
[ { "from": "human", "value": "\nYou are tasked with writing a Python function `find_max_books_path` that takes a hierarchical structure of a company's employees and the number of books each employee is donating, and returns the path through the hierarchy that results in the maximum number of books collected....
Write a Python program that reads a JSON configuration file and provides an interface to access the configuration settings. The JSON configuration file contains settings for database connection strings, logging levels, and allowed hosts, as shown in the given code snippet. The program should have the following funct...
```python import json class Configuration: def __init__(self, config_file): """ Initializes the Configuration object by loading the JSON configuration from the given file. :param config_file: Path to the JSON configuration file. """ try: with open(config_file,...
Here’s a Python program that meets your requirements for reading a JSON configuration file and providing an interface to access the configuration settings such as database connection strings, logging levels, and allowed hosts. The program includes error handling for file reading and JSON parsing. ### Configuration Fil...
10,321
[ { "from": "human", "value": "\n\nWrite a Python program that reads a JSON configuration file and provides an interface to access the configuration settings. The JSON configuration file contains settings for database connection strings, logging levels, and allowed hosts, as shown in the given code snippet.\n...
You are tasked with creating a Python function that will parse a JSON configuration file for a mobile application project and extract specific information to be used for setting up the project environment. The JSON configuration file contains information about the project, client details, OAuth clients, API keys, and...
```python import json def extract_project_setup_info(json_data): """ Extracts project setup information from a JSON configuration string or dictionary. Parameters: json_data (str or dict): A JSON configuration for a mobile application project. Returns: dict: A dictionary containing extracte...
You can create the `extract_project_setup_info` function as follows. This function will take in a JSON object (either as a string or dictionary), parse it, and extract the required fields while ensuring robustness against missing fields. Here's a sample implementation: ```python import json def extract_project_setup...
10,322
[ { "from": "human", "value": "\n\nYou are tasked with creating a Python function that will parse a JSON configuration file for a mobile application project and extract specific information to be used for setting up the project environment. The JSON configuration file contains information about the project, c...
Write a Python function `parse_angular_project_config` that takes a JSON string representing an Angular project configuration and returns a dictionary with specific details about the project. The function should extract the following information: - `projectType`: The type of the project (e.g., "application"). - `sty...
```python import json def parse_angular_project_config(json_string): """ Parses an Angular project configuration JSON string and extracts specific details. Parameters: json_string (str): A JSON string representing the Angular project configuration. Returns: dict: A dictionary containing ext...
To implement the `parse_angular_project_config` function that extracts specific details from an Angular project configuration JSON string, we can follow these steps: 1. Parse the JSON string into a Python dictionary. 2. Extract the required fields, ensuring to handle any missing or malformed data gracefully. 3. Return...
10,323
[ { "from": "human", "value": "\n\nWrite a Python function `parse_angular_project_config` that takes a JSON string representing an Angular project configuration and returns a dictionary with specific details about the project. The function should extract the following information:\n\n- `projectType`: The type...
You are given a JSON object representing a response from an e-commerce API. The response contains a list of sections, each with a list of products. Each product has a `product_id`, `product_thumb` (URL to the product's thumbnail image), and `product_name`. Write a Python function `extract_product_info(response)` tha...
```python import json def extract_product_info(response): """ Extracts product information from the given JSON response. :param response: A dictionary representing the JSON response from an API. :return: A list of dictionaries with 'section' and 'products' information. """ extracted_info...
Here's a Python function that extracts product information from the given JSON response, following the specifications you've provided: ```python def extract_product_info(response): result = [] # Iterate through each section in the response for section in response.get('sections', []): # Get the...
10,324
[ { "from": "human", "value": "\n\nYou are given a JSON object representing a response from an e-commerce API. The response contains a list of sections, each with a list of products. Each product has a `product_id`, `product_thumb` (URL to the product's thumbnail image), and `product_name`.\n\nWrite a Python ...
You are tasked with creating a Python function that processes a JSON object representing a menu of pizzas. The JSON object contains two categories: "pizzas" and "vegans". Each pizza item in the "pizzas" category has a "title", "description", and "imageURL". The "vegans" category is intended to list vegan pizza option...
```python import json def add_vegan_options(menu_json, vegan_options): """ Adds a list of vegan pizza options to the menu JSON object, ensuring no duplicate titles. :param menu_json: A JSON object representing the current menu. :param vegan_options: A list of dictionaries representing new vegan ...
To achieve the required functionality, we can create a Python function `add_vegan_options` that processes the JSON object and adds new vegan options while avoiding duplicates based on pizza titles. Below is a sample implementation of that function: ```python import json def add_vegan_options(menu, vegan_options): ...
10,325
[ { "from": "human", "value": "\n\nYou are tasked with creating a Python function that processes a JSON object representing a menu of pizzas. The JSON object contains two categories: \"pizzas\" and \"vegans\". Each pizza item in the \"pizzas\" category has a \"title\", \"description\", and \"imageURL\". The \...
You are tasked with creating a system that can process a list of crafting recipes for a futuristic game where players can craft various types of seeds using different components. Each recipe is represented as a JSON object with various attributes such as the result, category, skills required, and components needed. ...
```python import json # Given JSON data as a string for demonstration purposes json_data = ''' [ { "result": "rc_seed_amplifier", "type": "recipe", "category": "CC_FOOD", "subcategory": "CSC_FOOD_SEEDS", "skill_used": "fabrication", "skills_required": [ [ "cooking", 5 ], [ "fabrication", 5 ...
To create the function `get_recipe_details(recipe_name)`, we need to assume that we have access to a predefined list of crafting recipes, represented as JSON objects (or Python dictionaries). Below is an implementation that illustrates how to achieve this. First, let's define some sample data for the recipes, followed...
10,326
[ { "from": "human", "value": "\n\nYou are tasked with creating a system that can process a list of crafting recipes for a futuristic game where players can craft various types of seeds using different components. Each recipe is represented as a JSON object with various attributes such as the result, category...
Write a Python function `generate_minecraft_block_json` that takes two arguments: `block_name` (a string representing the name of the Minecraft block) and `texture_name` (a string representing the name of the texture for the block). The function should return a JSON string that represents a Minecraft block model with...
```python import json def generate_minecraft_block_json(block_name, texture_name): """ Generates a JSON string for a Minecraft block model with the specified block name and texture name. :param block_name: A string representing the name of the Minecraft block. :param texture_name: A string repre...
To create a function `generate_minecraft_block_json` that generates the appropriate JSON string based on the given parameters, we can use Python's built-in `json` module to handle the JSON formatting. Below is the implementation of the function along with test cases to verify the correctness of the output. ```python i...
10,327
[ { "from": "human", "value": "\n\nWrite a Python function `generate_minecraft_block_json` that takes two arguments: `block_name` (a string representing the name of the Minecraft block) and `texture_name` (a string representing the name of the texture for the block). The function should return a JSON string t...
You are given a JSON object representing a paginated list of music video details from a video streaming platform. The JSON object contains the current page number, page size, total number of pages, total number of results, and a list of items where each item contains details about a music video such as `videoId`, `ti...
```python import json def get_video_durations_by_group(json_data: str, group: str) -> int: """ Calculate the total duration of videos in a specific group. :param json_data: A JSON string containing video details. :param group: The group identifier to filter videos by. :return: The total duration...
To perform the task of calculating the total duration of music videos in a specified group from a JSON object, we can follow these steps: 1. **Parse the JSON String**: Convert the JSON string into a Python dictionary. 2. **Filter Videos by Group**: Use a list comprehension to filter out videos that belong to the speci...
10,328
[ { "from": "human", "value": "\n\nYou are given a JSON object representing a paginated list of music video details from a video streaming platform. The JSON object contains the current page number, page size, total number of pages, total number of results, and a list of items where each item contains details...
Given a JSON object representing adsorption isotherm data for a specific adsorbate on an adsorbent material, write a Python function `calculate_adsorption_at_pressure` that takes the JSON object and a target pressure value as inputs and returns the total adsorption value at that pressure. If the target pressure is no...
```python import json from typing import Dict, Any def calculate_adsorption_at_pressure(isotherm_json: Dict[str, Any], target_pressure: float) -> float: """ Estimates the total adsorption at a given target pressure using linear interpolation from the provided isotherm data in JSON format. :param iso...
Here's a Python function that implements the specified functionality. It takes a JSON object and a target pressure as input, performs linear interpolation, and returns the estimated total adsorption value. ```python import json from typing import Dict, List def calculate_adsorption_at_pressure(data: Dict, target_pres...
10,329
[ { "from": "human", "value": "\n\nGiven a JSON object representing adsorption isotherm data for a specific adsorbate on an adsorbent material, write a Python function `calculate_adsorption_at_pressure` that takes the JSON object and a target pressure value as inputs and returns the total adsorption value at ...
Given a JSON object representing a collection of experimental data, write a Python function `filter_data` that processes the data according to the following specifications: - The JSON object contains keys that are unique identifiers for each experiment (e.g., "AX", "CDD", "H1", etc.). - Each experiment has associate...
```python import json def filter_data(data): """ Filters out experiments with values outside the specified standard deviation bounds. :param data: A JSON object containing experimental data. :return: A new JSON object with outliers filtered out. """ filtered_data = {} for experiment, det...
Here is a Python function that implements the specifications you outlined for filtering experimental data from a JSON object. The function `filter_data` processes the input data, calculates the outlier bounds, and returns a new object with the filtered results. ```python import json def filter_data(data): """ ...
10,330
[ { "from": "human", "value": "\n\nGiven a JSON object representing a collection of experimental data, write a Python function `filter_data` that processes the data according to the following specifications:\n\n- The JSON object contains keys that are unique identifiers for each experiment (e.g., \"AX\", \"CD...
Write a Python function `parse_verification_results` that takes a JSON string representing the results of a Dafny verification process and returns a summary of the verification outcomes. The function should extract relevant information from the JSON data, such as the total runtime, termination reason, and a list of v...
```python import json from typing import Any, Dict, List def parse_verification_results(json_data: str) -> Dict[str, Any]: """ Parses the JSON string containing the results of a Dafny verification process and returns a summary of the verification outcomes. Parameters: - json_data: A JSON string ...
Certainly! Here's an implementation of the `parse_verification_results` function that extracts the required information from a Dafny verification process JSON string. The function uses the `json` module to parse the string and handles potential errors gracefully. Please note that you'll need to adapt the assumed stru...
10,331
[ { "from": "human", "value": "\n\nWrite a Python function `parse_verification_results` that takes a JSON string representing the results of a Dafny verification process and returns a summary of the verification outcomes. The function should extract relevant information from the JSON data, such as the total r...
Write a Python function `update_package_json` that takes a JSON string representing a `package.json` file (commonly used in Node.js projects) and updates it according to the following rules: 1. Increment the patch version of the package (the third number in the `version` field). 2. Add a new keyword `"updated"` to t...
```python import json from packaging import version def update_package_json(package_json): """ Updates the given package.json string according to the specified rules. Args: - package_json (str): A JSON string representing a package.json file. Returns: - str: The updated package.json string....
Here's a Python function `update_package_json` that fulfills the specified requirements for updating a `package.json` file represented as a JSON string. The function uses the `json` module to parse and manipulate the JSON data, and it incorporates the required logic for each rule. ```python import json import re def ...
10,332
[ { "from": "human", "value": "\n\nWrite a Python function `update_package_json` that takes a JSON string representing a `package.json` file (commonly used in Node.js projects) and updates it according to the following rules:\n\n1. Increment the patch version of the package (the third number in the `version` ...
Write a Python function `update_package_versions` that takes a JSON string representing a `package.json` file (commonly used in Node.js projects) and a dictionary of package names with their new versions. The function should update the versions of the specified packages in both `dependencies` and `devDependencies` se...
```python import json def update_package_versions(json_string: str, new_versions: dict) -> str: """ Updates the versions of specified packages in a package.json JSON string. :param json_string: A string containing the JSON content of package.json. :param new_versions: A dictionary where keys are pac...
Here’s a Python function that implements the `update_package_versions` as described in your request. This function parses the JSON input, updates the versions for the specified packages in both `dependencies` and `devDependencies`, and returns the modified JSON string. ```python import json def update_package_version...
10,333
[ { "from": "human", "value": "\n\nWrite a Python function `update_package_versions` that takes a JSON string representing a `package.json` file (commonly used in Node.js projects) and a dictionary of package names with their new versions. The function should update the versions of the specified packages in b...
Write a Python function `validate_package_json` that takes a JSON string representing a package.json file (commonly used in Node.js projects) and validates it against the following rules: 1. The `name` field must be a non-empty string. 2. The `version` field must be a non-empty string and follow semantic versioning....
```python import json import re from urllib.parse import urlparse def validate_package_json(json_string): """ Validates a package.json file content given as a JSON string. Parameters: - json_string: A string representing the package.json content. Returns: - A dictionary with keys 'valid' an...
To implement the `validate_package_json` function, we can follow these steps: 1. Parse the input JSON string into a Python dictionary. 2. Validate each field based on the provided rules, collecting any errors encountered. 3. Return a dictionary indicating if the input is valid and listing any errors. We also need hel...
10,334
[ { "from": "human", "value": "\n\nWrite a Python function `validate_package_json` that takes a JSON string representing a package.json file (commonly used in Node.js projects) and validates it against the following rules:\n\n1. The `name` field must be a non-empty string.\n2. The `version` field must be a no...
Write a Python function `update_package_version` that takes a JSON string representing a `package.json` file (commonly used in Node.js projects) and two arguments: `package_name` (a string) and `new_version` (a string). The function should update the version of the specified package in both `dependencies` and `devDep...
```python import json def update_package_version(package_json, package_name, new_version): """ Updates the version of a specified package in both dependencies and devDependencies within a package.json file. If the package does not exist, it is added to dependencies. :param package_json: A JSON s...
Here's a Python function that meets your requirements for updating a package's version in a `package.json` style JSON string. This function will correctly handle modifications to both `dependencies` and `devDependencies`, and will return the updated JSON string. ```python import json def update_package_version(json_s...
10,335
[ { "from": "human", "value": "\n\nWrite a Python function `update_package_version` that takes a JSON string representing a `package.json` file (commonly used in Node.js projects) and two arguments: `package_name` (a string) and `new_version` (a string). The function should update the version of the specified...
You are tasked with creating a Python script that reads a JSON configuration file for a TypeScript project and updates the compiler options based on certain rules. The script should perform the following actions: 1. If the `target` compiler option is set to "es2019", update it to "es2020". 2. If the `strict` compile...
```python import json def update_tsconfig(file_path): """ Reads a TypeScript configuration file, updates the compiler options based on certain rules, and writes the updated configuration to a new file named 'updated_tsconfig.json'. Args: - file_path: The path to the original TypeScript configura...
Certainly! Below is a Python script that fulfills the requirements specified in your task. It reads a `tsconfig.json` file, applies the necessary updates to the compiler options, and writes the updated configuration to a new file called `updated_tsconfig.json`. ```python import json import os def update_tsconfig(inpu...
10,336
[ { "from": "human", "value": "\n\nYou are tasked with creating a Python script that reads a JSON configuration file for a TypeScript project and updates the compiler options based on certain rules. The script should perform the following actions:\n\n1. If the `target` compiler option is set to \"es2019\", up...
You are tasked with creating a Python script that validates the structure of a JSON object representing a Node.js project's `package.json` file. The JSON object should contain specific fields that are essential for a Node.js project, such as `name`, `version`, `main`, `repository`, `author`, `license`, `type`, `scrip...
```python import json import re def validate_package_json(json_obj): """ Validates the structure of a Node.js project's package.json JSON object. Args: json_obj (dict): The JSON object to validate. Returns: tuple: A tuple containing a boolean indicating validity and a message string...
To validate the structure of a `package.json` object, we can create a Python function called `validate_package_json`. This function will check for the required fields, validate the format of the `repository` URL, and ensure that the `dependencies` field is a valid dictionary containing packages and their versions. Bel...
10,337
[ { "from": "human", "value": "\n\nYou are tasked with creating a Python script that validates the structure of a JSON object representing a Node.js project's `package.json` file. The JSON object should contain specific fields that are essential for a Node.js project, such as `name`, `version`, `main`, `repos...
Write a Python function `extract_package_info` that takes a JSON string representing a package information (similar to the given code snippet) and extracts specific details about the package. The function should return a dictionary containing the following information: - `name`: The name of the package. - `version`:...
```python import json def extract_package_info(json_string: str) -> dict: """ Extracts package information from a JSON string. Parameters: - json_string (str): A JSON string containing package information. Returns: - dict: A dictionary with keys 'name', 'version', 'license', 'author_name', ...
To extract specific package information from a JSON string, we can use Python's built-in `json` module to parse the string into a dictionary. We'll then extract the desired details while handling any potential missing data by returning `None` for missing keys. Here's the implementation: ```python import json def ext...
10,338
[ { "from": "human", "value": "\n\nWrite a Python function `extract_package_info` that takes a JSON string representing a package information (similar to the given code snippet) and extracts specific details about the package. The function should return a dictionary containing the following information:\n\n- ...
Write a Python function `update_package_json` that takes a JSON string representing a `package.json` file (similar to the one provided in the code snippet) and a dictionary of dependencies with their corresponding versions to be updated. The function should update the `package.json` JSON string with the new versions ...
```python import json def update_package_json(package_json_str, new_dependencies): """ Updates the dependencies in a package.json JSON string with new versions. :param package_json_str: A string containing the package.json content. :param new_dependencies: A dictionary with dependencies as keys ...
Here is the implementation of the function `update_package_json` that updates the dependencies in a `package.json` JSON string. Additionally, I've included test cases to ensure the correctness of the solution. ```python import json def update_package_json(package_json_str, dependencies): # Parse the original pack...
10,339
[ { "from": "human", "value": "\n\nWrite a Python function `update_package_json` that takes a JSON string representing a `package.json` file (similar to the one provided in the code snippet) and a dictionary of dependencies with their corresponding versions to be updated. The function should update the `packa...
Given a JSON object representing a collection of scientific measurements, write a Python function `calculate_confidence_intervals(data)` that calculates the 95% confidence interval for each measurement. The JSON object has the following structure: - Each key represents a unique measurement identifier (e.g., "Ax", "H...
```python import json def calculate_confidence_intervals(data): """ Calculate the 95% confidence intervals for a collection of scientific measurements. :param data: A JSON object containing measurement data. :return: A JSON object with the same keys, where each value contains the original mean v...
To calculate the 95% confidence intervals for the provided scientific measurements in a JSON object, we can define a Python function named `calculate_confidence_intervals(data)`. This function will iterate through each measurement entry, compute the confidence interval based on the provided mean (`value`) and standard ...
10,340
[ { "from": "human", "value": "\n\nGiven a JSON object representing a collection of scientific measurements, write a Python function `calculate_confidence_intervals(data)` that calculates the 95% confidence interval for each measurement. The JSON object has the following structure:\n\n- Each key represents a ...
You are tasked with writing a Python function that processes a JSON object representing a collection of image metadata. The JSON object has two main parts: an array of images, each with a filename, idiom, and scale, and an info object with author and version details. Your function, `process_image_metadata`, should r...
```python import json def process_image_metadata(json_data): """ Processes a JSON object containing image metadata and groups images by idiom. Images within each idiom group are sorted by their scale in ascending order. :param json_data: A JSON object containing image metadata. :return: A di...
Here's a Python function that processes the given JSON object containing image metadata according to the specified requirements. This function takes a JSON object as input, groups the images by `idiom`, sorts them by `scale`, and outputs a structured dictionary: ```python import json from collections import defaultdic...
10,341
[ { "from": "human", "value": "\n\nYou are tasked with writing a Python function that processes a JSON object representing a collection of image metadata. The JSON object has two main parts: an array of images, each with a filename, idiom, and scale, and an info object with author and version details.\n\nYour...
Write a Python program that processes a JSON object representing a petition's details and performs the following tasks: 1. Extracts the petition's state and signature count. 2. Determines if the petition was rejected due to being a duplicate. 3. Calculates the duration in days between the petition's creation and its...
```python import json from datetime import datetime # Importing the required packages from typing import Dict, Optional # Define the function to process the petition JSON def process_petition(petition_json: str) -> Dict[str, Optional[bool, int, str]]: """ Processes a JSON string representing a petition's de...
Certainly! Below is a Python program that processes a JSON object representing a petition's details according to the tasks you've specified. The program handles cases where certain dates might be `null`, and it generates a summary report containing the required information. ```python import json from datetime import...
10,342
[ { "from": "human", "value": "\n\nWrite a Python program that processes a JSON object representing a petition's details and performs the following tasks:\n\n1. Extracts the petition's state and signature count.\n2. Determines if the petition was rejected due to being a duplicate.\n3. Calculates the duration ...
Write a Python function `analyze_resource_prevalence` that takes a JSON object representing the tracking data of a domain and calculates the total prevalence of each resource type (Stylesheet, Image, Font, etc.) across all sites. The function should return a dictionary where the keys are the resource types and the val...
```python import json def analyze_resource_prevalence(data): """ Analyzes the total prevalence of each resource type in the given tracking data. :param data: A JSON object containing tracking data of a domain. :return: A dictionary with resource types as keys and total prevalence as values. "...
To accomplish this task, we need to parse the provided JSON object to aggregate the prevalence values of different resource types. Let's implement the `analyze_resource_prevalence` function step by step. Here's the complete implementation of the function: ```python import json def analyze_resource_prevalence(data): ...
10,343
[ { "from": "human", "value": "\nWrite a Python function `analyze_resource_prevalence` that takes a JSON object representing the tracking data of a domain and calculates the total prevalence of each resource type (Stylesheet, Image, Font, etc.) across all sites. The function should return a dictionary where t...
Write a Python function `validate_business_record` that takes a JSON string representing a business record and validates it against the following rules: 1. `cedula_rnc` must be a string of exactly 9 digits. 2. `nombre_razon_social` must be a non-empty string. 3. `nombre_comercial` can be either a non-empty string or...
```python import json import re from datetime import datetime def validate_business_record(json_string): """ Validates a business record JSON string against predefined rules. Parameters: json_string (str): A JSON string representing a business record. Returns: bool: True if the JSON...
To implement the function `validate_business_record`, we need to parse the JSON string into a Python dictionary and then perform several validation checks based on the rules you've provided. Below is a sample implementation of the function: ```python import json import re def validate_business_record(json_string): ...
10,344
[ { "from": "human", "value": "\n\nWrite a Python function `validate_business_record` that takes a JSON string representing a business record and validates it against the following rules:\n\n1. `cedula_rnc` must be a string of exactly 9 digits.\n2. `nombre_razon_social` must be a non-empty string.\n3. `nombre...
Create a Python function `analyze_tracking_data` that takes a JSON string representing tracking data for a domain and returns a summary of the tracking prevalence and types of tracking resources used. The function should parse the JSON data and extract the following information: 1. The domain name. 2. The total numbe...
```python import json def analyze_tracking_data(json_data): """ Analyzes tracking data from a JSON string and returns a summary of tracking information. :param json_data: A JSON string containing tracking data for a domain. :return: A dictionary summarizing the tracking prevalence and types of track...
To accomplish your request, we will create the Python function `analyze_tracking_data`. This function will parse a JSON string containing tracking data, extract the required information, and return it in the specified dictionary format. Here's how you can implement it: ```python import json from collections import def...
10,345
[ { "from": "human", "value": "\nCreate a Python function `analyze_tracking_data` that takes a JSON string representing tracking data for a domain and returns a summary of the tracking prevalence and types of tracking resources used. The function should parse the JSON data and extract the following informatio...
You are given a JSON object representing the configuration of a mobile application project. The JSON object contains information about the project, client details, OAuth clients, API keys, and services. Your task is to write a Python function `extract_client_ids(json_data)` that takes this JSON object as input and re...
```python import json def extract_client_ids(json_data): """ Extracts unique client IDs from the given JSON data. :param json_data: A dictionary representing the JSON object structure. :return: A list of unique client IDs. """ client_ids = set() # Extract client IDs from 'oauth_client' ...
To accomplish the task of extracting unique client IDs from the provided JSON object structure, we can define the function `extract_client_ids`. This function will navigate through the JSON structure to capture `client_id` values from both the `oauth_client` and `other_platform_oauth_client` sections. Below is the Pyt...
10,346
[ { "from": "human", "value": "\n\nYou are given a JSON object representing the configuration of a mobile application project. The JSON object contains information about the project, client details, OAuth clients, API keys, and services. Your task is to write a Python function `extract_client_ids(json_data)` ...
Write a Python function `parse_vulnerability_data` that takes a JSON string representing a vulnerability report and extracts specific information into a dictionary. The function should follow these requirements: - The function should import the necessary modules to handle JSON data. - The function should parse the J...
```python import json def parse_vulnerability_data(json_data): """ Parses a JSON string containing a vulnerability report and extracts specific information. Parameters: - json_data (str): A JSON string representing a vulnerability report. Returns: - dict: A dictionary containing the...
Here's a Python function `parse_vulnerability_data` that meets your requirements: ```python import json def parse_vulnerability_data(json_string): """ Parses a JSON string representing a vulnerability report and extracts specific information. Parameters: json_string (str): A JSON string containing th...
10,347
[ { "from": "human", "value": "\n\nWrite a Python function `parse_vulnerability_data` that takes a JSON string representing a vulnerability report and extracts specific information into a dictionary. The function should follow these requirements:\n\n- The function should import the necessary modules to handle...
Write a Python program that reads a JSON configuration file containing database connection strings and provides a function to retrieve a specific connection string by its name. The program should be able to handle cases where the requested connection string does not exist and return a suitable message. The JSON conf...
```python import json # Import the JSON module to work with JSON data def get_connection_string(name): """ Retrieves a database connection string by its name from a JSON configuration file. :param name: The name of the connection string to retrieve. :return: The connection string if found, othe...
Certainly! Below is a Python program that implements the requirements you specified. The program includes a function `get_connection_string(name)` that retrieves the connection string from a JSON configuration file, handling cases where the requested connection string does not exist. First, ensure you have a JSON conf...
10,348
[ { "from": "human", "value": "\n\nWrite a Python program that reads a JSON configuration file containing database connection strings and provides a function to retrieve a specific connection string by its name. The program should be able to handle cases where the requested connection string does not exist an...
You are given a list of trending topics on a social media platform, each represented as a JSON object with the following properties: `name`, `query`, `rank`, and `tweet_count`. The `tweet_count` is a string that represents the number of tweets associated with the topic, and it may sometimes be `null` if the count is ...
```python import json def filter_trending_topics(trending_topics: list, min_tweet_count: int) -> list: def tweet_count_to_int(tweet_count_str): if tweet_count_str is None: return 0 if 'K' in tweet_count_str: return int(float(tweet_count_str.replace('K Tweets', '').replace(...
Here's a Python function that implements the requirements described. This function filters trending topics based on a specified minimum tweet count, converts the `tweet_count` from a string to an integer for comparison, and sorts the results in descending order based on the `tweet_count`. ```python def filter_trending...
10,349
[ { "from": "human", "value": "\n\nYou are given a list of trending topics on a social media platform, each represented as a JSON object with the following properties: `name`, `query`, `rank`, and `tweet_count`. The `tweet_count` is a string that represents the number of tweets associated with the topic, and ...
You are tasked with creating a Python script that reads a JSON file containing configuration data for a Node.js project and updates the version of a specified dependency or devDependency. The script should take two command-line arguments: the name of the dependency to update and the new version number. After updating...
```python import json import sys from pathlib import Path def update_dependency_version(dependency_name, new_version): """ Updates the version of a specified dependency in the package.json file. Args: dependency_name (str): The name of the dependency to update. new_version (str): The new version...
To create the Python script `update_dependency_version.py` that updates the version of a specified dependency or devDependency in a Node.js `package.json` file, we will follow these steps: 1. Read the existing `package.json` file. 2. Parse the JSON data. 3. Check if the specified dependency exists in either `dependenc...
10,350
[ { "from": "human", "value": "\n\nYou are tasked with creating a Python script that reads a JSON file containing configuration data for a Node.js project and updates the version of a specified dependency or devDependency. The script should take two command-line arguments: the name of the dependency to update...
Write a Python function `update_package_info` that takes a JSON string representing a package information (similar to the given code snippet) and a dictionary of updates. The function should apply the updates to the package information and return the updated JSON string. The updates dictionary will contain keys that...
```python import json def update_package_info(json_string, updates): """ Updates the package information JSON string with the provided updates dictionary. :param json_string: A JSON string representing package information. :param updates: A dictionary containing updates to be applied to the pack...
Here is a Python function `update_package_info` that takes a JSON string representing package information and a dictionary of updates. It updates the package information according to the updates and returns the updated JSON string. The function also validates if the input JSON string is valid. ```python import json d...
10,351
[ { "from": "human", "value": "\n\nWrite a Python function `update_package_info` that takes a JSON string representing a package information (similar to the given code snippet) and a dictionary of updates. The function should apply the updates to the package information and return the updated JSON string.\n\n...
Write a Python function `filter_stories_by_genre` that takes a list of story metadata (in the form of dictionaries like the given code snippet) and a target genre. The function should return a list of story metadata dictionaries that belong to the specified genre. The function should also handle the case where the ge...
```python def filter_stories_by_genre(stories: list, genre: str) -> list: """ Filters a list of story metadata dictionaries by a specific genre. Parameters: - stories (list): A list of dictionaries, each representing the metadata of a story. - genre (str): The target genre to filter the stories b...
You can implement the `filter_stories_by_genre` function as described in the prompt. This function will go through each story dictionary in the provided list and check if the `genre` key matches the specified genre. If it does, the story will be added to the result list. If no stories match the genre, the function will...
10,352
[ { "from": "human", "value": "\n\nWrite a Python function `filter_stories_by_genre` that takes a list of story metadata (in the form of dictionaries like the given code snippet) and a target genre. The function should return a list of story metadata dictionaries that belong to the specified genre. The functi...
Write a Python function `extract_vulnerability_details(json_data)` that takes a JSON object representing a vulnerability report and extracts specific details about the vulnerability. The function should return a dictionary containing the following information: - `cve_id`: The Common Vulnerabilities and Exposures (CV...
```python import json def extract_vulnerability_details(json_data): """ Extracts details about a vulnerability from a JSON object. Parameters: json_data (dict): A JSON object representing a vulnerability report. Returns: dict: A dictionary containing the CVE ID, description, impact score, ...
To extract specific details from a JSON object that represents a vulnerability report, we can define the function `extract_vulnerability_details(json_data)`. This function will attain the required fields from the received JSON dictionary and return a new dictionary with the extracted data. Here's an implementation of ...
10,353
[ { "from": "human", "value": "\n\nWrite a Python function `extract_vulnerability_details(json_data)` that takes a JSON object representing a vulnerability report and extracts specific details about the vulnerability. The function should return a dictionary containing the following information:\n\n- `cve_id`:...
You are given a JSON string representing the configuration of various packages used in a software project. The JSON structure contains information about the version of the configuration, a list of packages with their details, and metadata about when and how the configuration was generated. Write a Python function `g...
```python import json def get_packages_by_language_version(json_string, language_version): """ Extracts package names from the provided JSON string that match the specified language version. :param json_string: A JSON string representing the configuration of packages. :param language_version: A ...
To create the function `get_packages_by_language_version`, we will use Python's built-in `json` module to parse the JSON string. We will then iterate over the list of packages to filter out those that match the specified `language_version`. The following implementation adheres to the requirements set forth: ```python ...
10,354
[ { "from": "human", "value": "\n\nYou are given a JSON string representing the configuration of various packages used in a software project. The JSON structure contains information about the version of the configuration, a list of packages with their details, and metadata about when and how the configuration...
You are tasked with creating a Python function that reads a JSON file containing information about a .NET project's NuGet package restore configuration and extracts certain details about the project's framework dependencies and package sources. The JSON structure is similar to the given code snippet, which represent...
```python import json def extract_project_details(file_path): """ Reads a JSON file containing a .NET project's NuGet package restore configuration and extracts details about the project's framework dependencies and package sources. Parameters: file_path (str): The file path to the JSON conf...
To create the `extract_project_details` function that extracts the required information from a JSON file containing NuGet package restore configuration, you can follow the steps below. The function will use Python's built-in `json` module to read and parse the JSON data. Here's the implementation: ```python import js...
10,355
[ { "from": "human", "value": "\n\nYou are tasked with creating a Python function that reads a JSON file containing information about a .NET project's NuGet package restore configuration and extracts certain details about the project's framework dependencies and package sources.\n\nThe JSON structure is simil...
Design a RESTful API for a blogging platform, where users can interact with articles and comments. Your task is to create a Python function `api_request_handler` that simulates the handling of various HTTP requests to the API. The function should take two arguments: `request_type` (a string representing the HTTP meth...
```python import json # Importing json to simulate the API response data def api_request_handler(request_type, endpoint, data=None): """ Simulates the handling of HTTP requests to a blogging platform API. :param request_type: A string representing the HTTP method ('GET', 'POST', 'PATCH', 'DELETE')....
Below is an implementation of the `api_request_handler` function simulating a RESTful blogging platform. The function supports different HTTP methods, handles valid endpoints, and allows for different parameters as specified. It simulates in-memory data storage for articles, topics, users, and comments. ```python def ...
10,356
[ { "from": "human", "value": "\n\nDesign a RESTful API for a blogging platform, where users can interact with articles and comments. Your task is to create a Python function `api_request_handler` that simulates the handling of various HTTP requests to the API. The function should take two arguments: `request...
You are tasked with writing a Python function `filter_books_by_language` that filters a list of books based on the language specified. Each book is represented as a dictionary with the following keys: "Title", "Language", "Authors", "License", and "PublicationDate". The function should return a new list containing on...
```python def filter_books_by_language(books, language): """ Filters a list of books based on the specified language. :param books: A list of dictionaries, where each dictionary represents a book with keys: "Title", "Language", "Authors", "License", and "PublicationDate". :param...
Certainly! Below is the implementation of the function `filter_books_by_language`, which filters a list of books based on a specified language. The function iterates over the list of books and checks if the `Language` key matches the specified language. If it does, the book is added to the new list which is then return...
10,357
[ { "from": "human", "value": "\n\nYou are tasked with writing a Python function `filter_books_by_language` that filters a list of books based on the language specified. Each book is represented as a dictionary with the following keys: \"Title\", \"Language\", \"Authors\", \"License\", and \"PublicationDate\"...
You are tasked with creating a Python function `parse_exploit_details` that extracts information from a JSON object representing a cybersecurity exploit. The function should return a dictionary with specific details about the exploit. The JSON object has the following structure: ```json { "exploit": { "...
```python import json def parse_exploit_details(exploit_json): """ Extracts details about a cybersecurity exploit from a JSON object and returns a dictionary with specific information. Parameters: exploit_json (str): A JSON string representing the exploit details. Returns: dict: A dictionar...
To create the `parse_exploit_details` function that extracts the specified details from a JSON object representing a cybersecurity exploit, we will need to navigate through the JSON structure to gather the required fields. Here's how you can implement this function in Python: ```python def parse_exploit_details(exploi...
10,358
[ { "from": "human", "value": "\n\nYou are tasked with creating a Python function `parse_exploit_details` that extracts information from a JSON object representing a cybersecurity exploit. The function should return a dictionary with specific details about the exploit.\n\nThe JSON object has the following str...
You are given a JSON object representing a collection of software packages with their respective metadata. Each key in the JSON object is the name of a software package, and the value is another JSON object containing the following metadata about the package: - `arch`: The architecture for which the package is built...
```python import json def compare_versions(version1, version2): """ Compare two version strings numerically and return True if version1 >= version2. """ # Split the version strings into parts parts1 = version1.split('-')[0].split('.') parts2 = version2.split('-')[0].split('.') # Conv...
To filter the packages based on their versions, we need a function that can properly compare version strings numerically. We'll split each version into its components (like major, minor, patch) and convert them into integers for accurate comparison. Here's how you can implement the `filter_packages_by_version()` funct...
10,359
[ { "from": "human", "value": "\n\nYou are given a JSON object representing a collection of software packages with their respective metadata. Each key in the JSON object is the name of a software package, and the value is another JSON object containing the following metadata about the package:\n\n- `arch`: Th...
Design a Python function `validate_comment_structure` that takes a JSON object representing a comment and checks if it adheres to a predefined structure similar to the one described in the given code snippet. The function should ensure that the JSON object has the correct type and required properties as specified in ...
```python import json def validate_comment_structure(comment_json): """ Validates if the given JSON object adheres to the predefined comment structure. :param comment_json: A JSON object representing a comment. :return: True if the JSON object is valid, otherwise raises a ValueError. """ ...
You can implement the `validate_comment_structure` function in Python as follows. This function checks if the input JSON object matches the specified requirements for the `comment_id` and `initial_comments` properties. ```python def validate_comment_structure(comment_json): # Check if input is a dictionary (JSON o...
10,360
[ { "from": "human", "value": "\n\nDesign a Python function `validate_comment_structure` that takes a JSON object representing a comment and checks if it adheres to a predefined structure similar to the one described in the given code snippet. The function should ensure that the JSON object has the correct ty...
Write a Python function `parse_package_info` that takes a JSON string representing a package information and returns a dictionary with specific details about the package and its head version. The function should extract the following details: - `name`: The name of the package. - `url`: The URL of the package reposit...
```python import json def parse_package_info(json_str): """ Parses a JSON string containing package information and extracts specific details. Parameters: - json_str: A JSON string representing the package information. Returns: A dictionary with the following keys: - name: The n...
Here's a Python function `parse_package_info` that processes a JSON string containing package information and extracts the required details into a dictionary. If any of the required fields are missing or empty, the function will set the corresponding value in the output dictionary to `None`. ```python import json def...
10,361
[ { "from": "human", "value": "\n\nWrite a Python function `parse_package_info` that takes a JSON string representing a package information and returns a dictionary with specific details about the package and its head version. The function should extract the following details:\n\n- `name`: The name of the pac...
A software company is developing a system to manage employee information across different departments. They require a JSON structure to represent the list of departments and the employees within each department. Each department can have multiple employees, and each employee has a unique ID, a name, and a role. Write...
```python import json def create_department_json(departments, employee_info): """ Creates a JSON string representing the structure of an organization with departments and employees. :param departments: A list of department names. :param employee_info: A dictionary with employee ID as keys and a ...
To create the required function `create_department_json`, we will leverage the Python `json` module to construct the JSON structure based on the specified format. Here’s how we can implement this: 1. The function will accept a list of department names and a dictionary of employees. 2. For each department, we will crea...
10,362
[ { "from": "human", "value": "\n\nA software company is developing a system to manage employee information across different departments. They require a JSON structure to represent the list of departments and the employees within each department. Each department can have multiple employees, and each employee ...
You are tasked with creating a Python script that reads a `package.json` file (like the one provided in the code snippet) and performs the following operations: 1. Extracts the `dependencies` and `devDependencies` and lists them separately. 2. For each dependency, it should determine if the version is fixed (no care...
```python import json from typing import Dict, List # Importing the necessary packages import json def categorize_dependencies(package_json: Dict) -> Dict[str, List[str]]: """ Categorizes dependencies from a package.json file into fixed and variable. :param package_json: A dictionary representing the p...
To achieve the task of extracting dependencies and categorizing them by fixed or variable versions from a `package.json` file, we can create a Python script. Below is the detailed implementation: ```python import json def read_package_json(file_path): with open(file_path, 'r') as file: return json.load(fi...
10,363
[ { "from": "human", "value": "\n\nYou are tasked with creating a Python script that reads a `package.json` file (like the one provided in the code snippet) and performs the following operations:\n\n1. Extracts the `dependencies` and `devDependencies` and lists them separately.\n2. For each dependency, it sho...
You are tasked with creating a Python function `parse_repository_info` that takes a string representing a repository's metadata in JSON format and extracts specific information about the repository. The function should return a dictionary containing the repository's name, the number of GitHub stars, the version of th...
```python import json import re def parse_repository_info(repo_metadata): """ Parses a string containing repository metadata and returns a dictionary with specific details. :param repo_metadata: A string containing the repository's metadata in JSON format. :return: A dictionary with the repository's...
To create the `parse_repository_info` function as described in your request, we need to extract data from the given input string, which combines both repository information and JSON metadata. The function will perform the following steps: 1. Split the input string to separate the repository name and the star count fro...
10,364
[ { "from": "human", "value": "\n\nYou are tasked with creating a Python function `parse_repository_info` that takes a string representing a repository's metadata in JSON format and extracts specific information about the repository. The function should return a dictionary containing the repository's name, th...
Design a Python program that interacts with a virtual real estate platform, where users can add, buy, rent, and manage virtual lands. The platform is represented by a JSON-based API (as provided in the given code snippet), which simulates the behavior of smart contracts on a blockchain. Your program should be able to...
```python import json # Simulate the JSON-based API provided in the given code snippet api_json = """ [Your JSON here] """ # Parse the JSON to simulate the smart contract's functions api_data = json.loads(api_json) # Define the virtual real estate platform class class VirtualRealEstatePlatform: def __init__(se...
Sure! Below is a Python program that simulates interactions with a virtual real estate platform as described. This program uses a mock API represented by JSON data to perform actions like adding, buying, renting, and managing virtual lands. We'll create a class to represent the interface with the virtual real estate p...
10,365
[ { "from": "human", "value": "\n\nDesign a Python program that interacts with a virtual real estate platform, where users can add, buy, rent, and manage virtual lands. The platform is represented by a JSON-based API (as provided in the given code snippet), which simulates the behavior of smart contracts on a...
Given a list of trending topics on a social media platform, each represented as a JSON object with the properties `name`, `query`, `rank`, and `tweet_count`, write a Python function `filter_trending_topics` that filters out topics with a `tweet_count` of `None` or less than a specified threshold. The function should ...
```python import re def filter_trending_topics(trending_topics: list, min_tweet_count: int) -> list: """ Filters and sorts trending topics based on tweet count and rank. :param trending_topics: A list of dictionaries, each representing a trending topic with keys 'name', 'query', 'rank', and 'tweet_count...
To implement the `filter_trending_topics` function as described, we need to break down the requirements into steps: 1. **Filtering**: We need to ignore topics where `tweet_count` is `None` or less than the specified `min_tweet_count`. 2. **Parsing**: The `tweet_count` is given in a format like "166K Tweets". We'll nee...
10,366
[ { "from": "human", "value": "\n\nGiven a list of trending topics on a social media platform, each represented as a JSON object with the properties `name`, `query`, `rank`, and `tweet_count`, write a Python function `filter_trending_topics` that filters out topics with a `tweet_count` of `None` or less than ...
You are tasked with creating a Python function that can parse a JSON object representing the localization data for a web application's interface. The JSON object contains various keys that map to strings or nested objects with further strings. Some of these strings contain placeholders (e.g., `{{ param }}` or `{{ id ...
```python import json def replace_placeholders(text, replacements): """Replace placeholders in the text with their corresponding values.""" for key, value in replacements.items(): placeholder = "{{ " + key + " }}" text = text.replace(placeholder, value) return text def localize_interface...
To create the `localize_interface` function as specified, we will need to implement a recursive approach that can navigate through the JSON structure, identify the placeholders, and replace them with the provided values. Here's how we can accomplish this: ```python import json def localize_interface(json_data, replac...
10,367
[ { "from": "human", "value": "\n\nYou are tasked with creating a Python function that can parse a JSON object representing the localization data for a web application's interface. The JSON object contains various keys that map to strings or nested objects with further strings. Some of these strings contain p...
Write a Python function `parse_package_info` that takes a JSON string representing a package information (similar to the given code snippet, which is a typical `package.json` file from a Node.js project) and returns a dictionary with specific details about the package. The function should extract the following infor...
```python import json def parse_package_info(json_string): """ Parses a JSON string containing package information and extracts specific details. Parameters: json_string (str): A JSON string representing package information. Returns: dict: A dictionary with extracted package details...
To create a function `parse_package_info`, we'll use the built-in `json` module to parse the JSON string. The function will extract the specified fields, taking care to handle cases where certain fields may be absent. Here's the implementation of the function: ```python import json def parse_package_info(package_jso...
10,368
[ { "from": "human", "value": "\n\nWrite a Python function `parse_package_info` that takes a JSON string representing a package information (similar to the given code snippet, which is a typical `package.json` file from a Node.js project) and returns a dictionary with specific details about the package.\n\nTh...
Write a Python function `update_debug_configuration` that takes a JSON string representing a debug configuration for a development environment (similar to the one provided in the code snippet) and updates it according to the following requirements: 1. Change the `version` to "1.0.0". 2. Add a new argument `"--verbos...
```python import json def update_debug_configuration(json_str): """ Updates the given debug configuration JSON string. :param json_str: A JSON string representing the debug configuration. :return: An updated JSON string with the version set to "1.0.0", an additional argument "--verbose", ...
To create the `update_debug_configuration` function in Python, we will follow the requirements you provided. The function will parse a JSON string, perform the specified updates, and then return the updated JSON string. Here is the implementation: ```python import json def update_debug_configuration(json_string): ...
10,369
[ { "from": "human", "value": "\n\nWrite a Python function `update_debug_configuration` that takes a JSON string representing a debug configuration for a development environment (similar to the one provided in the code snippet) and updates it according to the following requirements:\n\n1. Change the `version`...
Design a Python function `parse_vulnerability_data` that takes a JSON string representing a vulnerability report and extracts specific information into a Python dictionary. The function should adhere to the following requirements: - The function should extract the following fields from the JSON data: - `id`: The u...
```python import json from typing import Dict, List, Any def parse_vulnerability_data(json_data: str) -> Dict[str, Any]: """ Parses a JSON string containing vulnerability report data and extracts specific information into a dictionary. Parameters: - json_data (str): A JSON string representing a ...
Here is a Python function `parse_vulnerability_data` that accomplishes the specified requirements: ```python import json def parse_vulnerability_data(json_string): """ Parses a vulnerability report JSON string and extracts relevant information. Parameters: json_string (str): A JSON string representin...
10,370
[ { "from": "human", "value": "\n\nDesign a Python function `parse_vulnerability_data` that takes a JSON string representing a vulnerability report and extracts specific information into a Python dictionary. The function should adhere to the following requirements:\n\n- The function should extract the followi...
Write a Python function `update_package_info` that takes a JSON string representing a package information similar to the given code snippet and updates the package information based on the provided updates. The function should follow these specifications: - The function should accept two arguments: `json_str` (the J...
```python import json def update_package_info(json_str, updates): """ Updates the package information based on the provided updates dictionary. Parameters: - json_str (str): A JSON string representing the package information. - updates (dict): A dictionary containing the updates to be applied. ...
To create the `update_package_info` function according to the specifications you've provided, you'll need to use the `json` module for parsing and creating JSON. The function will parse the input string, update the relevant fields if they exist in the original data, and return the updated information as a JSON string. ...
10,371
[ { "from": "human", "value": "\n\nWrite a Python function `update_package_info` that takes a JSON string representing a package information similar to the given code snippet and updates the package information based on the provided updates. The function should follow these specifications:\n\n- The function s...
You are tasked with creating a Python function `filter_playlist_by_resolution` that filters a playlist of video entries based on the desired resolution. The playlist is provided in JSON format, where each video entry contains a `title` and a `url`. The resolution can be inferred from the title, which includes the res...
```python import json def filter_playlist_by_resolution(playlist_json, resolution): """ Filters a playlist of video entries based on the desired resolution. Args: - playlist_json (str): A JSON string representing the playlist. - resolution (str): The desired resolution to filter by ("HD" or ...
Certainly! Here’s a Python function `filter_playlist_by_resolution` that meets the requirements you've provided. The function will filter the videos from a playlist based on the desired resolution ("HD" for 1080p and "4K" for 2160p) and will return a new JSON string containing only the videos that match the specified r...
10,372
[ { "from": "human", "value": "\n\nYou are tasked with creating a Python function `filter_playlist_by_resolution` that filters a playlist of video entries based on the desired resolution. The playlist is provided in JSON format, where each video entry contains a `title` and a `url`. The resolution can be infe...
Write a Python function `parse_vulnerability_data` that takes a JSON string representing a vulnerability report and returns a dictionary with specific details about the vulnerability. The function should extract the following information: - `id`: The unique identifier of the vulnerability. - `published_date`: The da...
```python import json def parse_vulnerability_data(json_data): """ Parses a JSON string containing a vulnerability report and extracts specific details. Parameters: - json_data (str): A JSON string representing a vulnerability report. Returns: - dict: A dictionary with extracted details inc...
Certainly! Below is a Python function named `parse_vulnerability_data` that takes a JSON string representing a vulnerability report and extracts the specified details into a dictionary. The function ensures to handle missing fields appropriately by assigning `None` to individual missing fields and creating an empty lis...
10,373
[ { "from": "human", "value": "\n\nWrite a Python function `parse_vulnerability_data` that takes a JSON string representing a vulnerability report and returns a dictionary with specific details about the vulnerability. The function should extract the following information:\n\n- `id`: The unique identifier of ...
Write a Python function `update_key_bindings` that takes a JSON string representing a configuration file (similar to the one provided in the code snippet) and a dictionary of new key bindings. The function should update the existing key bindings in the JSON configuration with the new ones provided in the dictionary. ...
```python import json def update_key_bindings(config_json, new_bindings): """ Updates the key bindings in the given JSON configuration with the new key bindings provided. :param config_json: A JSON string representing the configuration file. :param new_bindings: A dictionary with command names a...
To create the `update_key_bindings` function that updates the key bindings in a JSON configuration represented as a string, you can follow these steps: 1. Parse the JSON string to convert it into a Python dictionary. 2. Update the existing key bindings in the dictionary with the new ones provided. 3. Convert the updat...
10,374
[ { "from": "human", "value": "\n\nWrite a Python function `update_key_bindings` that takes a JSON string representing a configuration file (similar to the one provided in the code snippet) and a dictionary of new key bindings. The function should update the existing key bindings in the JSON configuration wit...
You are tasked with creating a Python function `analyze_tracking_data` that processes JSON data representing tracking information for a domain. The function should analyze the tracking data and return a summary of the tracking prevalence, the types of tracking resources, and the top initiators of tracking. The JSON ...
```python import json def analyze_tracking_data(tracking_json): """ Analyze tracking data from a JSON object and return a summary of tracking prevalence, resource types, and the top initiator. :param tracking_json: JSON object containing tracking data :return: Dictionary with total prevalence, r...
To create the `analyze_tracking_data` function that processes the given JSON structure and analyzes tracking data, you can follow the outlined logic in the problem. Below is a Python implementation of the function, assuming the structure of the JSON data is clear based on your description. Here is a possible implement...
10,375
[ { "from": "human", "value": "\n\nYou are tasked with creating a Python function `analyze_tracking_data` that processes JSON data representing tracking information for a domain. The function should analyze the tracking data and return a summary of the tracking prevalence, the types of tracking resources, and...
Given a JSON object representing a collection of bus stop features, write a Python function `extract_bus_routes` that extracts a list of unique bus routes from the features. Each feature contains properties about the bus stop, including a `route_ref:De_Lijn` key that lists the bus routes serving that stop. The functi...
```python import json def extract_bus_routes(feature_collection): """ Extracts a sorted list of unique bus route numbers from a feature collection. :param feature_collection: A dictionary representing a collection of bus stop features. :return: A sorted list of unique bus route numbers as intege...
To achieve the task of extracting a unique list of bus routes from the JSON object, we can follow these steps: 1. Loop through each feature in the `features` array. 2. Check if the `route_ref:De_Lijn` key is present in the `properties` of the feature. 3. If it is present, split the string by the semicolon (`;`) to get...
10,376
[ { "from": "human", "value": "\n\nGiven a JSON object representing a collection of bus stop features, write a Python function `extract_bus_routes` that extracts a list of unique bus routes from the features. Each feature contains properties about the bus stop, including a `route_ref:De_Lijn` key that lists t...
Write a Python program that reads a JSON file containing package information similar to the given code snippet and performs the following tasks: 1. Extracts the name, version, and description of the package. 2. Checks if the package has any dependencies, and if so, lists all the dependencies along with their version...
```python import json def read_package_info(file_path): """ Reads a JSON file containing package information and performs various checks. Args: file_path (str): The path to the JSON file. Returns: None """ try: with open(file_path, 'r') as file: package_i...
Certainly! Below is a Python program that performs the tasks you specified. It reads a JSON file containing package information and processes it accordingly. Make sure to update the file path to the correct JSON file containing your package data. ```python import json import os def read_package_info(file_path): t...
10,377
[ { "from": "human", "value": "\n\nWrite a Python program that reads a JSON file containing package information similar to the given code snippet and performs the following tasks:\n\n1. Extracts the name, version, and description of the package.\n2. Checks if the package has any dependencies, and if so, lists...
Write a Python function `update_package_json` that takes a JSON string representing a `package.json` file (commonly used in Node.js projects) and updates it according to the following rules: 1. Increment the minor version of the project (e.g., 1.0.0 -> 1.1.0). 2. Add a new script named "test" with the command "jest"...
```python import json def update_package_json(package_json): """ Updates the package.json string according to the specified rules. :param package_json: A JSON string representing a package.json file. :return: An updated JSON string with the applied changes. """ # Parse the JSON string in...
Here's a Python function `update_package_json` that accomplishes the specified requirements for updating a `package.json` JSON string. ```python import json import re def update_package_json(package_json_str): # Parse the input JSON string package_json = json.loads(package_json_str) # 1. Increment the mi...
10,378
[ { "from": "human", "value": "\n\nWrite a Python function `update_package_json` that takes a JSON string representing a `package.json` file (commonly used in Node.js projects) and updates it according to the following rules:\n\n1. Increment the minor version of the project (e.g., 1.0.0 -> 1.1.0).\n2. Add a n...
You are tasked with creating a Python function that processes information about a collection of Non-Fungible Tokens (NFTs). Each NFT is represented as a JSON object similar to the one provided in the code snippet. Your function should be able to filter NFTs based on specific attribute criteria and return a list of NF...
```python import json def filter_nfts_by_attribute(nfts, criteria): """ Filters a list of NFTs based on specific attribute criteria. Parameters: nfts (list of dict): A list of NFTs, where each NFT is represented as a dictionary. criteria (dict): A dictionary of attribute criteria to filter the N...
You can create the function `filter_nfts_by_attribute` to filter NFTs based on the specified criteria. Here's a sample implementation: ```python def filter_nfts_by_attribute(nfts, criteria): filtered_nfts = [] for nft in nfts: # Check if all criteria match the NFT's attributes matches_all_crit...
10,379
[ { "from": "human", "value": "\n\nYou are tasked with creating a Python function that processes information about a collection of Non-Fungible Tokens (NFTs). Each NFT is represented as a JSON object similar to the one provided in the code snippet. Your function should be able to filter NFTs based on specific...
You are tasked with creating a Python function `analyze_domain_data` that takes a JSON string representing domain information and performs various analyses on it. The function should return a dictionary with the following keys and their corresponding values: 1. `domain_owner`: The name of the owner of the domain. 2....
```python import json def analyze_domain_data(json_data): """ Analyzes domain information from a JSON string and returns a dictionary with specific details. :param json_data: A JSON string containing domain information. :return: A dictionary with analysis results. """ # Parse the JSON data ...
To implement the function `analyze_domain_data`, we will first parse the JSON string to extract the relevant information. We will then compute the required analyses and return them in a dictionary format. Let's assume the expected structure of the input JSON string contains the relevant fields such as `owner`, `sites`,...
10,380
[ { "from": "human", "value": "\n\nYou are tasked with creating a Python function `analyze_domain_data` that takes a JSON string representing domain information and performs various analyses on it. The function should return a dictionary with the following keys and their corresponding values:\n\n1. `domain_ow...
Write a Python function `extract_definitions(json_data)` that takes a JSON object representing a dictionary entry for a word and extracts the definitions of the word in all its grammatical forms (adjectives, nouns, verbs, etc.). The JSON object follows the structure provided in the given code snippet. The function s...
```python import json def extract_definitions(json_data): """ Extracts definitions from a JSON object representing a dictionary entry. :param json_data: A JSON object containing word definitions. :return: A dictionary with grammatical forms as keys and lists of definitions as values. """ res...
Certainly! Below is a Python function `extract_definitions` that takes a JSON object representing a dictionary entry for a word and extracts the definitions based on the grammatical forms. First, make sure you have the JSON object structured as described in your example. Here’s how you can implement the `extract_defin...
10,381
[ { "from": "human", "value": "\n\nWrite a Python function `extract_definitions(json_data)` that takes a JSON object representing a dictionary entry for a word and extracts the definitions of the word in all its grammatical forms (adjectives, nouns, verbs, etc.). The JSON object follows the structure provided...
Write a Python program that updates the Python interpreter path in a given JSON configuration file. The program should take two arguments: the path to the JSON configuration file and the new Python interpreter path. The JSON configuration file contains a single key `"python.pythonPath"` that stores the current path t...
```python import json import os def update_python_path(config_path, new_python_path): """ Updates the Python interpreter path in the JSON configuration file. :param config_path: Path to the JSON configuration file. :param new_python_path: The new Python interpreter path to be set. :return: None ...
Below is a Python program that implements the described functionality. It updates the Python interpreter path in a given JSON configuration file while handling various edge cases: ```python import json import os import sys def update_python_path(json_path, new_python_path): # Check if the provided path is a valid...
10,382
[ { "from": "human", "value": "\n\nWrite a Python program that updates the Python interpreter path in a given JSON configuration file. The program should take two arguments: the path to the JSON configuration file and the new Python interpreter path. The JSON configuration file contains a single key `\"python...
Design a Python function `validate_schema` that takes a JSON object representing the schema of a database table and validates it against a set of predefined rules. The JSON object is similar to the given code snippet, which includes the table's name, properties, and schema details such as column names, types, and oth...
```python import json def validate_schema(schema_json): """ Validates a JSON object representing a database table schema. :param schema_json: JSON object containing the schema details :return: True if the schema is valid, otherwise raises ValueError """ # Rule 1: The `name` field must be a n...
Here's a Python function named `validate_schema` that implements the specified validation rules for a given JSON object representing the schema of a database table. This function checks each rule and raises a `ValueError` with a specific error message if any rule is violated. ```python import json def validate_schem...
10,383
[ { "from": "human", "value": "\n\nDesign a Python function `validate_schema` that takes a JSON object representing the schema of a database table and validates it against a set of predefined rules. The JSON object is similar to the given code snippet, which includes the table's name, properties, and schema d...
Write a Python function `update_package_versions` that takes a JSON string representing a `package.json` file (commonly used in JavaScript projects) and a dictionary of package updates. The function should update the versions of the packages specified in the updates dictionary within the `dependencies` and `devDepend...
```python import json def update_package_versions(json_string: str, updates: dict) -> str: """ Updates the package versions in the given JSON string. :param json_string: A string representation of a package.json file. :param updates: A dictionary where keys are package names and values are the new v...
To implement the `update_package_versions` function, you want to parse the input JSON string, update the `dependencies` and `devDependencies` sections based on the given updates dictionary, and then serialize the modified data back into a JSON string. Below is a Python function that accomplishes this: ```python impo...
10,384
[ { "from": "human", "value": "\n\nWrite a Python function `update_package_versions` that takes a JSON string representing a `package.json` file (commonly used in JavaScript projects) and a dictionary of package updates. The function should update the versions of the packages specified in the updates dictiona...
Create a Python function `validate_business_record` that takes a JSON string representing a business record and validates it against the following rules: 1. `cedula_rnc` must be a string of 11 digits. 2. `nombre_razon_social` must be a non-empty string and trimmed of any excess whitespace. 3. `nombre_comercial` can ...
```python import json import re from datetime import datetime def validate_business_record(json_record): """ Validates a business record JSON string against specific rules. Parameters: json_record (str): A JSON string representing a business record. Returns: tuple: (bool, str) indicating if...
Certainly! Below is a Python function `validate_business_record` that implements the validation logic according to the specified rules. It takes a JSON string as input, parses it, and checks each rule, returning a tuple indicating whether the record is valid and a message. ```python import json import re from datetime...
10,385
[ { "from": "human", "value": "\n\nCreate a Python function `validate_business_record` that takes a JSON string representing a business record and validates it against the following rules:\n\n1. `cedula_rnc` must be a string of 11 digits.\n2. `nombre_razon_social` must be a non-empty string and trimmed of any...
Write a Python function `update_package_versions(package_data, updates)` that takes a JSON object representing a `package.json` file (like the one provided in the code snippet) and a dictionary `updates` where keys are package names and values are the new versions to be set. The function should update the versions of...
```python import json def update_package_versions(package_data, updates): """ Update the versions of packages in the package_data JSON object based on the updates dictionary. :param package_data: A JSON object representing a package.json file. :param updates: A dictionary where keys are package name...
Certainly! Below is a Python function `update_package_versions` that takes a JSON object representing a `package.json` file and a dictionary of updates. It updates the versions of the packages found in both `dependencies` and `devDependencies` sections: ```python def update_package_versions(package_data, updates): ...
10,386
[ { "from": "human", "value": "\n\nWrite a Python function `update_package_versions(package_data, updates)` that takes a JSON object representing a `package.json` file (like the one provided in the code snippet) and a dictionary `updates` where keys are package names and values are the new versions to be set....
Write a Python function `extract_user_messages` that takes a JSON string representing a list of message objects (as shown in the given code snippet) and returns a dictionary where each key is a user ID and the corresponding value is a list of messages (text content) sent by that user. The messages should be ordered by...
```python import json from typing import List, Dict def extract_user_messages(json_string: str) -> Dict[str, List[str]]: """ Extracts messages from a JSON string and groups them by user ID. :param json_string: A JSON string representing a list of message objects. :return: A dictionary with user IDs a...
To accomplish the task of extracting user messages from a JSON string and organizing them in a dictionary by user ID while preserving the order of their timestamps, we can write the function `extract_user_messages`. Below is the implementation of the function along with a brief explanation. ```python import json def ...
10,387
[ { "from": "human", "value": "\nWrite a Python function `extract_user_messages` that takes a JSON string representing a list of message objects (as shown in the given code snippet) and returns a dictionary where each key is a user ID and the corresponding value is a list of messages (text content) sent by th...
Write a Python program that reads a JSON object representing a software package configuration and performs the following tasks: 1. Validates the JSON object against the following criteria: - `homepage`, `license`, `version`, `url`, and `hash` keys must be present and their values must be non-empty strings. - ...
```python import json import re # Importing required packages from jsonschema import validate from jsonschema.exceptions import ValidationError # JSON schema for validation schema = { "type": "object", "properties": { "homepage": {"type": "string", "minLength": 1}, "license": {"type": "string...
Certainly! Below is a Python program that implements the tasks you described for validating a software package configuration JSON object. The program reads the JSON, verifies it against the specified criteria, extracts the version, generates a download URL, and provides appropriate error handling. ```python import jso...
10,388
[ { "from": "human", "value": "\nWrite a Python program that reads a JSON object representing a software package configuration and performs the following tasks:\n\n1. Validates the JSON object against the following criteria:\n - `homepage`, `license`, `version`, `url`, and `hash` keys must be present and t...
You are tasked with creating a Python function that validates and updates a JSON object representing a Spark job configuration for a data processing task. The JSON object should conform to a specific schema, similar to the one provided in the given code snippet. The function should perform the following tasks: 1. Va...
```python import json import re def validate_azure_blob_path(path): pattern = r"^abfss://[a-z0-9]+@[a-z0-9]+\.dfs\.core\.windows\.net/.+$" return re.match(pattern, path) is not None def validate_memory_format(memory): pattern = r"^\d+[gG]$" return re.match(pattern, memory) is not None def update_sp...
To accomplish the task of validating and updating a JSON object representing the Spark job configuration, we can implement the `update_spark_job_config` function. Below is the Python code for this function: ```python import json import re def is_valid_azure_blob_path(path): """ Validates if the given path is ...
10,389
[ { "from": "human", "value": "\n\nYou are tasked with creating a Python function that validates and updates a JSON object representing a Spark job configuration for a data processing task. The JSON object should conform to a specific schema, similar to the one provided in the given code snippet. The function...
Write a Python program that reads a JSON file containing package information and updates the version number of the package following semantic versioning rules. The program should take two arguments: the path to the JSON file and the type of version update (major, minor, or patch). After updating the version, the prog...
```python import json import sys from packaging.version import Version def update_version(json_file_path, update_type): """ Updates the version number of a package in a JSON file based on the update type. Args: json_file_path (str): The path to the JSON file containing the package information. u...
Here's a Python program that accomplishes this task. It reads a JSON file containing package information, updates the version according to the specified type of update (major, minor, or patch), and writes the updated information back to the JSON file. ```python import json import sys import os def update_version(vers...
10,390
[ { "from": "human", "value": "\n\nWrite a Python program that reads a JSON file containing package information and updates the version number of the package following semantic versioning rules. The program should take two arguments: the path to the JSON file and the type of version update (major, minor, or p...
Write a Python function `update_package_version(package_json, package_name, new_version)` that takes a JSON string representing a `package.json` file (like the one provided in the snippet), the name of a package, and a new version number as input. The function should update the version of the specified package in the...
```python import json def update_package_version(package_json, package_name, new_version): """ Updates the version of a specified package in the dependencies or devDependencies of a package.json file. :param package_json: A JSON string representing a package.json file. :param package_name: The n...
Here's a Python function `update_package_version` that updates the version of a specified package in a `package.json` JSON string. Additionally, I'll include test cases to verify that the functionality works as expected. ```python import json def update_package_version(package_json, package_name, new_version): # ...
10,391
[ { "from": "human", "value": "\n\nWrite a Python function `update_package_version(package_json, package_name, new_version)` that takes a JSON string representing a `package.json` file (like the one provided in the snippet), the name of a package, and a new version number as input. The function should update ...
You are tasked with creating a configuration manager that can read, update, and save settings for a software development environment. The settings are stored in a JSON file, which includes visual customizations for the workbench and default configurations for certain tools. The JSON structure is as shown in the given...
```python import json import os class ConfigurationManager: def __init__(self, config_file): self.config_file = config_file self.settings = self.load_settings() def load_settings(self): """Load settings from a JSON file.""" try: with open(self.config_file, 'r') as...
Sure! Below is a Python program that fulfills the requirements for a configuration manager that loads, updates, and saves settings from a JSON file. It includes error handling for file operations and provides meaningful messages in case of errors. ```python import json import os class ConfigurationManager: def __...
10,392
[ { "from": "human", "value": "\n\nYou are tasked with creating a configuration manager that can read, update, and save settings for a software development environment. The settings are stored in a JSON file, which includes visual customizations for the workbench and default configurations for certain tools. ...
Write a Python function `update_package_versions` that takes a JSON string representing a `package.json` file (commonly found in Node.js projects) and a dictionary of package updates. The function should update the versions of the specified packages in both `dependencies` and `devDependencies` sections of the JSON. I...
```python import json def update_package_versions(package_json, updates): """ Update the versions of packages in a package.json file. :param package_json: A string representation of a package.json file. :param updates: A dictionary where keys are package names and values are the new versions. :r...
Here's a Python function `update_package_versions` that updates the versions of specified packages in a given JSON string representation of a `package.json` file. The function uses the `json` module to parse and generate the updated JSON string and takes care of error handling. ```python import json def update_packag...
10,393
[ { "from": "human", "value": "\n\nWrite a Python function `update_package_versions` that takes a JSON string representing a `package.json` file (commonly found in Node.js projects) and a dictionary of package updates. The function should update the versions of the specified packages in both `dependencies` an...
You are tasked with creating a Python script that reads a JSON file containing information about a web project, and then generates a report summarizing the project details and its dependencies. The report should include the project name, version, description, author, and a list of both production and development depe...
```python import json def generate_project_report(json_file_path): """ Generates a project report from a JSON file containing project details. :param json_file_path: Path to the JSON file. :return: A string containing the formatted project report. """ with open(json_file_path, 'r') as file: ...
Certainly! Below is the Python function `generate_project_report(json_file_path)` that reads a JSON file formatted like a `package.json`, extracts the relevant information, and generates the desired project report. To accomplish this, we'll use the `json` module to read the JSON file and process the required fields. T...
10,394
[ { "from": "human", "value": "\n\nYou are tasked with creating a Python script that reads a JSON file containing information about a web project, and then generates a report summarizing the project details and its dependencies. The report should include the project name, version, description, author, and a l...
Write a Python function `extract_repo_details` that takes a JSON string representing a GitHub repository's details and extracts specific information about the repository. The function should return a dictionary with the following keys and their corresponding values from the JSON: - `id`: The unique identifier for th...
```python import json def extract_repo_details(json_str): """ Extracts specific details from a JSON string representing a GitHub repository. Parameters: json_str (str): A JSON string containing the repository details. Returns: dict: A dictionary with extracted repository details. """ ...
Certainly! Below is a Python function named `extract_repo_details` that takes a JSON string representing a GitHub repository's details, extracts the specified information, and returns it as a dictionary. If any of the required keys are missing, the function will set the corresponding value to `None`. Here's the implem...
10,395
[ { "from": "human", "value": "\n\nWrite a Python function `extract_repo_details` that takes a JSON string representing a GitHub repository's details and extracts specific information about the repository. The function should return a dictionary with the following keys and their corresponding values from the ...
Given a list of subtitle entries where each entry is a dictionary containing the `text` of the subtitle, the `start` time in seconds, and the `duration` of the subtitle in seconds, write a Python function `merge_subtitles` that merges consecutive subtitles with the same text into a single subtitle entry. The merged e...
```python from typing import List, Dict, Union def merge_subtitles(subtitles: List[Dict[str, Union[str, float]]]) -> List[Dict[str, Union[str, float]]]: merged_subtitles = [] current_subtitle = None for subtitle in subtitles: if current_subtitle and subtitle['text'] == current_subtitle['text']: ...
To merge consecutive subtitles with the same text into a single entry, we can use a simple loop to iterate through the list of subtitle entries. We'll keep track of the current subtitle being merged and add to its duration until we encounter a different text or a non-consecutive subtitle. Once a change is detected, we'...
10,396
[ { "from": "human", "value": "\n\nGiven a list of subtitle entries where each entry is a dictionary containing the `text` of the subtitle, the `start` time in seconds, and the `duration` of the subtitle in seconds, write a Python function `merge_subtitles` that merges consecutive subtitles with the same text...
Design a Python function `extract_charging_station_info` that takes a JSON object representing the data of an electric vehicle charging station and extracts specific information into a more readable format. The function should return a dictionary with the following keys and their corresponding values: - `verified`: ...
```python import json def extract_charging_station_info(station_data): """ Extracts and returns essential information from a JSON object representing an electric vehicle charging station. Parameters: - station_data (dict): A dictionary representing the JSON data of the charging station. ...
To design the `extract_charging_station_info` function as specified, we can outline the function to parse a given JSON object representing the electric vehicle charging station data. It will extract the relevant information and return it in a well-structured dictionary. Here is the implementation of the function: ```...
10,397
[ { "from": "human", "value": "\n\nDesign a Python function `extract_charging_station_info` that takes a JSON object representing the data of an electric vehicle charging station and extracts specific information into a more readable format. The function should return a dictionary with the following keys and ...
Create a Python function `extract_transit_data_info(json_data)` that takes a JSON object representing metadata about a transit data study and extracts specific information into a more readable and structured dictionary format. The function should return a dictionary with the following keys and their corresponding val...
```python import json def extract_transit_data_info(json_data): """ Extracts specific information from a JSON object representing metadata about a transit data study. Parameters: json_data (dict): A JSON object containing metadata about the transit data study. Returns: dict: A dicti...
Sure! Below is the implementation of the `extract_transit_data_info` function in Python that extracts relevant information from a JSON object representing metadata about a transit data study. ```python def extract_transit_data_info(json_data): # Initialize the resulting dictionary with default values as None r...
10,398
[ { "from": "human", "value": "\n\nCreate a Python function `extract_transit_data_info(json_data)` that takes a JSON object representing metadata about a transit data study and extracts specific information into a more readable and structured dictionary format. The function should return a dictionary with the...
You are tasked with writing a Python program that processes a JSON configuration for firmware builds of IoT devices. The JSON structure contains information about different builds for various chip families, including the parts that need to be flashed onto the devices with their respective file paths and offsets. You...
```python import json # JSON data as a string for demonstration purposes json_data = ''' { "name": "ESPEasy including pxlBlck plugin", "version": "18.06.2022", "new_install_prompt_erase": true, "new_install_improv_wait_time": 0, "funding_url": "https://esphome.io/guides/supporters.html", "builds": [ ...
Certainly! Below is a Python program that processes the given JSON structure. It includes the `get_build_info(chip_family)` function to retrieve information about parts for a specified chip family, as well as the `is_new_install_prompt_erase()` function to check if a new installation should prompt to erase existing dat...
10,399
[ { "from": "human", "value": "\n\nYou are tasked with writing a Python program that processes a JSON configuration for firmware builds of IoT devices. The JSON structure contains information about different builds for various chip families, including the parts that need to be flashed onto the devices with th...