2

I want to try to make a little webserver where you can put location data into a database using a grid system in Javascript. I've found a setup that I really liked and maked an example in CodePen: https://codepen.io/anon/pen/XGxEaj. A user can click in a grid to point out the location. In the console log I see the data that is generated as output. For every cell in the grid it has a dictionary that looks like this:

click: 4
height: 50
width: 50
x: 1
xnum: 1
y: 1
ynum: 1

A complete overview of output data looks like this, where their are 10 arrays for every row, 10 arrays for every column of that row, and then a dictionary with the values: enter image description here

Now i want to get this information back to python in a dictionary as well, so i can store particular information in a database. But I can't figure out what the best way is to do that. Hopefully you could provide a little push in the right direction, links to usefull pages or code snippets to guide me.

Thanks for any help in advance!

2
  • This doesn't have anything to do with javascript. You just need to look into parsing json in Python, docs.python.org/2/library/json.html. Commented Mar 23, 2019 at 22:14
  • json stringify on js/ client side and json module on python/ server side maybe Commented Mar 23, 2019 at 22:22

2 Answers 2

2

This can be achieved by converting your JS object into JSON:

var json = JSON.stringify(myJsObj);

And then converting your Python object to JSON:

import json
myPythonObj = json.loads(json)

More information about the JSON package for Python can be found here and more information about converting JS objects to and from JSON can be found here

Sign up to request clarification or add additional context in comments.

Comments

1

You should use the python json module.

Here is how you can perform such operation using the module.

import json
json_data = '{"a": 1, "b": 2, "c": 3, "d": 4, "e": 5}'
loaded_json = json.loads(json_data)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.