Consistency in Running Python in Pabby Script.
Status: Closed · Asked by IChild Company on · 0 views
Dear Support & Community.
We have consistency issue running the following script in Pabbly Python.
The script is as such:
import json
def search_preschool(json_data, search_string):
# Parse the JSON data
data = json.loads(json_data)
# Search for the exact string in the 'name' field
for entry in data:
if search_string == entry['name']:
return entry['id'], entry['name']
# If no match is found, return a default message
return "No group found", "No group found"
# Example JSON data
json_data = '''[{"id":"[email hidden]","name":"MindChamps@Woodlands"},
{"id":"[email hidden]","name":"Brilliant Tots@PotongP"},
{"id":"[email hidden]","name":"Carpe Diem@Bukit Batok"},
{"id":"[email hidden]","name":"MindChamps@Thomson C"},
{"id":"[email hidden]","name":"GUG@Katong V EA"},
{"id":"[email hidden]","name":"Red Schhse@Woodleigh NE"},
{"id":"[email hidden]","name":"Twinklekidz@Bendemeer"},
{"id":"[email hidden]","name":"First Step@Jurong"},
{"id":"[email hidden]","name":"Da Little Preschool@Cecil"},
{"id":"[email hidden]","name":"ChildFirst@Dunearn EA"},
{"id":"[email hidden]","name":"First Step@SK (Initium)"},
{"id":"[email hidden]","name":"NurtureStar@Tampines PS"},
{"id":"[email hidden]","name":"Safari House"}]'''
# Search string
search_string = "1. GroupName : Blue House Kay Siang HR"
# Call the function
id, name = search_preschool(json_data, search_string)
# Return the results
return id, name
The above results is No group found, No group found
The above works when we use the above exhaustive JSON list.
However when we use the the API to get the JSON list from another application, the attached error is shown.
Kindly advise what is the issue?
Attachments




Is there a more efficient way to search through using the JSON extraction method?
Dear Support & Community.
We have consistency issue running the following script in Pabbly Python.The script is as such:
import json
def search_preschool(json_data, search_string):
# Parse the JSON data
data = json.loads(json_data)# Search for the exact string in the 'name' field
for entry in data:
if search_string == entry['name']:
return entry['id'], entry['name']# If no match is found, return a default message
return "No group found", "No group found"# Example JSON data
json_data = '''[{"id":"[EMAIL][email hidden][/EMAIL]","name":"MindChamps@Woodlands"},
{"id":"[EMAIL][email hidden][/EMAIL]","name":"Brilliant Tots@PotongP"},
{"id":"[EMAIL][email hidden][/EMAIL]","name":"Carpe Diem@Bukit Batok"},
{"id":"[EMAIL][email hidden][/EMAIL]","name":"MindChamps@Thomson C"},
{"id":"[EMAIL][email hidden][/EMAIL]","name":"GUG@Katong V EA"},
{"id":"[EMAIL][email hidden][/EMAIL]","name":"Red Schhse@Woodleigh NE"},
{"id":"[EMAIL][email hidden][/EMAIL]","name":"Twinklekidz@Bendemeer"},
{"id":"[EMAIL][email hidden][/EMAIL]","name":"First Step@Jurong"},
{"id":"[EMAIL][email hidden][/EMAIL]","name":"Da Little Preschool@Cecil"},
{"id":"[EMAIL][email hidden][/EMAIL]","name":"ChildFirst@Dunearn EA"},
{"id":"[EMAIL][email hidden][/EMAIL]","name":"First Step@SK (Initium)"},
{"id":"[EMAIL][email hidden][/EMAIL]","name":"NurtureStar@Tampines PS"},
{"id":"[EMAIL][email hidden][/EMAIL]","name":"Safari House"}]'''# Search string
search_string = "1. GroupName : Blue House Kay Siang HR"# Call the function
id, name = search_preschool(json_data, search_string)# Return the results
return id, nameThe above results is No group found, No group found
The above works when we use the above exhaustive JSON list.
However when we use the the API to get the JSON list from another application, the attached error is shown.
Kindly advise what is the issue?
The following has no issue. The code runs and provides the required
import json
def search_preschool(json_data, search_string):
# Parse the JSON data
data = json.loads(json_data)
# Search for the exact string in the 'name' field
for entry in data:
if search_string == entry['name']:
return entry['id'], entry['name']
# If no match is found, return a default message
return "No group found", "No group found"
# Example JSON data line18
json_data = '''[{"id":"noProblem","name":"MindChamps@ C"}]'''
# Search string
search_string = "MindChamps@Thomson C"
# Call the function
id, name = search_preschool(json_data, search_string)
# Return the results
return id, name
Attachments


Hey @ichilddev
We have reviewed the code, and corrected several syntax errors, and it is now functioning as expected. Additionally, with OpenAI's assistance, you can generate the code as needed.

import json
def search_preschool(json_data, search_string):
# Parse the JSON data
data = json.loads(json_data)
# Search for the exact string in the 'name' field
for entry in data:
if search_string == entry['name']:
return entry['id'], entry['name']
# If no match is found, return a default message
return "No group found", "No group found"
# Example JSON data
json_data = '''[{"id":"[email hidden]","name":"MindChamps@Woodlands"},
{"id":"[email hidden]","name":"Brilliant Tots@PotongP"},
{"id":"[email hidden]","name":"Carpe Diem@Bukit Batok"},
{"id":"[email hidden]","name":"MindChamps@Thomson C"},
{"id":"[email hidden]","name":"GUG@Katong V EA"},
{"id":"[email hidden]","name":"Red Schhse@Woodleigh NE"},
{"id":"[email hidden]","name":"Twinklekidz@Bendemeer"},
{"id":"[email hidden]","name":"First Step@Jurong"},
{"id":"[email hidden]","name":"Da Little Preschool@Cecil"},
{"id":"[email hidden]","name":"ChildFirst@Dunearn EA"},
{"id":"[email hidden]","name":"First Step@SK (Initium)"},
{"id":"[email hidden]","name":"NurtureStar@Tampines PS"},
{"id":"[email hidden]","name":"Safari House"}]'''
# Search string
search_string = "1. GroupName : Blue House Kay Siang HR"
# Call the function
id, name = search_preschool(json_data, search_string)
# Print the results
print(id, name)