Answer to #1 - thanks to @mccannf
Using JQuery.param:
Client:
var test = {"coordinates":[[-122.610168,37.598167],[-122.288818,37.598167],[-122.288818,37.845833],[-122.610168,37.845833],[-122.610168,37.598167]]};
console.log($.param( test ));
Outputs:
coordinates%5B0%5D%5B%5D=-122.610168&coordinates%5B0%5D%5B%5D=37.598167&coordinates%5B1%5D%5B%5D=-122.288818&coordinates%5B1%5D%5B%5D=37.598167&coordinates%5B2%5D%5B%5D=-122.288818&coordinates%5B2%5D%5B%5D=37.845833&coordinates%5B3%5D%5B%5D=-122.610168&coordinates%5B3%5D%5B%5D=37.845833&coordinates%5B4%5D%5B%5D=-122.610168&coordinates%5B4%5D%5B%5D=37.598167
Answer to #2 - thanks to @Brad:
Server - Express route:
router.get('/search_polygon', function(req, res) {
console.log('Server received: ' + JSON.stringify(req.query.coordinates));
...
Outputs:
Server received: [["-122.610168","37.598167"],["-122.288818","37.598167"],["-122.288818","37.845833"],["-122.610168","37.845833"],["-122.610168","37.598167"]]
My issue was trying to pass these as part of the path, and not as parameters as they should be.
JQuery.param, then you can just access the coordinates usingreq.query.coordinates[x][y]in the route in Express.dataor something. There are lots of ways to handle this, but the last thing I would do in this case is attach it to part of the path.req.querynotreq.params.