Created
April 13, 2023 05:59
-
-
Save gorborukov/4f70d85022e329e299204261035adb89 to your computer and use it in GitHub Desktop.
Removing fields from JSONL dataset
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'json' | |
# Read the JSON data from the original file line by line | |
modified_data = '' | |
File.foreach('original_file.jsonl') do |line| | |
# Parse the line as a JSON object | |
json_object = JSON.parse(line) | |
# Remove the 'category' and 'context' fields from the JSON object | |
json_object.delete('category') | |
json_object.delete('context') | |
# Convert the modified JSON object back into a JSON string and append it to the modified data variable | |
modified_data << JSON.generate(json_object) << "\n" | |
end | |
# Write the modified JSON data to a new file | |
File.write('modified_file.jsonl', modified_data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment