I'm having a bit of trouble creating a JSON array in python and returning it to PHP.
Right now I have a PHP page that calls a Python script like this:
$output1 = shell_exec("cd .. && cd python/pyjira && pipenv run py PyJira/Jira.py");
var_dump($output1);
The python script creates some JSON prints
if __name__ == "__main__":
jira = Jira()
data = {}
fields = jira.get_fields()
jql_issues = jira.get_jql_search_issues(jql_search="project = SWAT AND resolution = Unresolved ORDER BY priority DESC, updated DESC")
for issue in jql_issues:
data['key'] = issue.key
data['assignee'] = issue.fields.assignee.display_name
print(json.dumps(data))
exit
The output from python
{"key": "SWAT-107", "assignee": "Unassigned"}
{"key": "SWAT-98", "assignee": "Unassigned"}
{"key": "SWAT-100", "assignee": "Unassigned"}
{"key": "SWAT-97", "assignee": "Unassigned"}
{"key": "SWAT-75", "assignee": "Unassigned"}
{"key": "SWAT-129", "assignee": "Unassigned"}
This is the var_dump(...); from PHP, and here you can see it's multiple JSON's in a single string
"{"key": "SWAT-107", "assignee": "Unassigned"} {"key": "SWAT-98", "assignee": "Unassigned"} {"key": "SWAT-100", "assignee": "Unassigned"} {"key": "SWAT-97", "assignee": "Unassigned"} {"key": "SWAT-75", "assignee": "Unassigned"} {"key": "SWAT-129", "assignee": "Unassigned"} "
Is there a way to have python returning the JSON object one by one, so I can loop though them in PHP, and just do data['key'] etc.?
I know when I just have one of the JSON's from the outout like {"key": "SWAT-107", "assignee": "Unassigned"} the I just need to json_decode(...)_; it in PHP.
Update
As the comment suggested, I now tried to return a array from python, and get this on the PHP site:
"['{"key": "SWAT-106", "assignee": "Unassigned"}', '{"key": "SWAT-107", "assignee": "Unassigned"}', '{"key": "SWAT-98", "assignee": "Unassigned"}', '{"key": "SWAT-100", "assignee": "Unassigned"}', '{"key": "SWAT-97", "assignee": "Unassigned"}', '{"key": "SWAT-75", "assignee": "Unassigned"}', '{"key": "SWAT-129", "assignee": "Unassigned"}'] "
How can I make it into a array?
[{"key": "somevalue", "assignee": "othervalue"}, {"key": "value", "assignee": "anothervalue"}]. Then you canjson_decodeit just fine.