-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ensure JSON is not stringified #3
Comments
It seems to me like this is a limitation of pg_featureserv itself. I can think of three ways to solve this:
from flask import Flask, request, jsonify
import requests
import json
app = Flask(__name__)
@app.route('/forward-request', methods=['GET'])
def forward_request():
# Assuming the target URL is stored in the TARGET_URL environment variable or hardcoded
target_url = "http://example.com/target-server" # Replace with your target server URL
# Forward the incoming query parameters to the target server
response = requests.get(target_url, params=request.args)
# Check if the request was successful
if response.status_code == 200:
try:
# Try to parse the JSON response
data = response.json()
# Extract, parse, and replace the 'tags' value within 'data["properties"]'
if "properties" in data and "tags" in data["properties"]:
tags_json_str = data["properties"]["tags"]
tags_json = json.loads(tags_json_str) # Convert the string to JSON
data["properties"]["tags"] = tags_json # Replace the string with the JSON object
# Return the modified JSON
return jsonify(data)
except ValueError:
# In case the response is not in JSON format or parsing failed
return jsonify({"error": "Invalid JSON response from target server"}), 500
else:
return jsonify({"error": "Failed to fetch data from target server"}), 500
if __name__ == '__main__':
app.run(debug=True) What do you think? |
I think the best way is to fix this directly in pg_featureserv |
Alright, well I will need to learn a lot more about Go before I am able to fix it there. Do you have an idea on how to fix it? I would love to see how you do it to see how to work on a Go codebase properly. |
I need to get into the code base as well but we can also have a look together |
this fix might solve this issue: CrunchyData/pg_featureserv#165 |
currently our response is:
we want to have the
tags
property to be a proper JSONrelated CrunchyData/pg_featureserv#155
The text was updated successfully, but these errors were encountered: