Skip to content

Commit

Permalink
jsonify input, add output array (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
royshil authored Nov 4, 2023
1 parent 49b5b81 commit 3f5479e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/request-data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,19 @@ struct request_data_handler_response request_data_handler(url_source_request_dat
}
request_data->last_obs_text_source_value = text;
}
json["input"] = text;
// if one of the headers is Content-Type application/json, make sure the text is JSONified
std::string textStr = text;
for (auto header : request_data->headers) {
if (header.first == "Content-Type" &&
header.second == "application/json") {
nlohmann::json tmp = text;
textStr = tmp.dump();
// remove '"' from the beginning and end of the string
textStr = textStr.substr(1, textStr.size() - 2);
break;
}
}
json["input"] = textStr;
}

// Replace the {input} placeholder with the source text
Expand Down
2 changes: 2 additions & 0 deletions src/url-source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ void curl_loop(struct url_source_data *usd)
data["output" + std::to_string(i)] =
response.body_parts_parsed[i];
}
// in "output" add an array of all the outputs
data["output"] = response.body_parts_parsed;
} else {
data["output"] = response.body_parts_parsed[0];
}
Expand Down

0 comments on commit 3f5479e

Please sign in to comment.