To extract all the JSON file names from the given text, you can use regular expressions. Here's a Python code snippet that does this:
pythonCopyEditimport re
Sample text containing JSON file paths
text = '''
{"payload":{"allShortcutsEnabled":false,"path":"tasks","repo":{"id":375765893,"defaultBranch":"master","name":"natural-instructions","ownerLogin":"allenai","currentUserCanPush":false,"isFork":false,"isEmpty":false,"createdAt":"2021-06-10T16:39:52.000Z","ownerAvatar":"https://avatars.githubusercontent.com/u/5667695?v=4","public":true,"private":false,"isOrgOwned":true},"currentUser":null,"refInfo":{"name":"master","listCacheKey":"v0:(688)797-9117.054417","canEdit":false,"refType":"branch","currentOid":"XXX"},"tree":{"items":[{"name":"README.md","path":"tasks/README.md","contentType":"file"},{"name":"task001_quoref_question_generation.json","path":"tasks/task001_quoref_question_generation.json","contentType":"file"},{"name":"task002_quoref_answer_generation.json","path":"tasks/task002_quoref_answer_generation.json","contentType":"file"},{"name":"task003_mctaco_question_generation_event_duration.json","path":"tasks/task003_mctaco_question_generation_event_duration.json","contentType":"file"},{"name":"task004_mctaco_answer_generation_event_duration.json","path":"tasks/task004_mctaco_answer_generation_event_duration.json","contentType":"file"},{"name":"task005_mctaco_wrong_answer_generation_event_duration.json","path":"tasks/task005_mctaco_wrong_answer_generation_event_duration.json","contentType":"file"},{"name":"task006_mctaco_question_generation_transient_stationary.json","path":"tasks/task006_mctaco_question_generation_transient_stationary.json","contentType":"file"},{"name":"task007_mctaco_answer_generation_transient_stationary.json","path":"tasks/task007_mctaco_answer_generation_transient_stationary.json","contentType":"file"},{"name":"task008_mctaco_wrong_answer_generation_transient_stationary.json","path":"tasks/task008_mctaco_wrong_answer_generation_transient_stationary.json","contentType":"file"},{"name":"task009_mctaco_question_generation_event_ordering.json","path":"tasks/task009_mctaco_question_generation_event_ordering.json","contentType":"file"},{"name":"task010_mctaco_answer_generation_event_ordering.json","path":"tasks/task010_mctaco_answer_generation_event_ordering.json","contentType":"file"},{"name":"task011_mctaco_wrong_answer_generation_event_ordering.json","path":"tasks/task011_mctaco_wrong_answer_generation_event_ordering.json","contentType":"file"},{"name":"task012_mctaco_question_generation_absolute_timepoint.json","path":"tasks/task012_mctaco_question_generation_absolute_timepoint.json","contentType":"file"},{"name":"task013_mctaco_answer_generation_absolute_timepoint.json","path":"tasks/task013_mctaco_answer_generation_absolute_timepoint.json","contentType":"file"},{"name":"task014_mctaco_wrong_answer_generation_absolute_timepoint.json","path":"tasks/task014_mctaco_wrong_answer_generation_absolute_timepoint.json","contentType":"file"},{"name":"task015_mctaco_question_generation_frequency.json","path":"tasks/task015_mctaco_question_generation_frequency.json","contentType":"file"},{"name":"task016_mctaco_answer_generation_frequency.json","path":"tasks/task016_mctaco_answer_generation_frequency.json","contentType":"file"},{"name":"task017_mctaco_wrong_answer_generation_frequency.json","path":"tasks/task017_mctaco_wrong_answer_generation_frequency.json","contentType":"file"},{"name":"task018_mctaco_temporal_reasoning_presence.json","path":"tasks/task018_mctaco_temporal_reasoning_presence.json","contentType":"file"},{"name":"task019_mctaco_temporal_reasoning_category.json","path":"tasks/task019_mctaco_temporal_reasoning_category.json","contentType":"file"}
'''
Define a regular expression pattern to match JSON file paths
pattern = r'"path":"(.*?.json)"'
Use the findall method to extract all matches
json_file_names = re.findall(pattern, text)
Print the extracted JSON file names
for file_name in json_file_names:
print(file_name)
This code defines a regular expression pattern to match JSON file paths and then uses the re.findall() function to extract all matching file paths. It will print the JSON file names like this:
bashCopyEdittasks/task001_quoref_question_generation.json
tasks/task002_quoref_answer_generation.json
tasks/task003_mctaco_question_generation_event_duration.json
... and so on for all JSON file names
You can replace the text variable with your actual input text containing the JSON file paths to extract the names from your specific text.