I cannot make JSON data correctly. (The result of below has duplicate data 
with the word <Row: 

result = dict()
for r in new_roots:
   result[r] = '{"title": '  +  '"' + r.taxonomy_column_name +  '"' +   ', 
"key":' +   str(r.id) +  ', "parentId":' + '2' + ', "folder": false, 
"lazy": true},'

Output looks like below.

{<Row {'taxonomy_column_name': 'Battlespace Networks', 
'taxonomy_column_parent_fk': 17L, 'id': 18L}>: '{"title": "Battlespace 
Networks", "key":18, "parentId":2, "folder": false, "lazy": true},', <Row 
{'taxonomy_column_name': 'Municipality', 'taxonomy_column_parent_fk': 24L, 
'id': 26L}>: '{"title": "Municipality", "key":26, "parentId":2, "folder": 
false, "lazy": true},', <Row {'taxonomy_column_name': 'Service cross 
reference', 'taxonomy_column_parent_fk': 14L, 'id': 15L}>: '{"title": 
"Service cross reference", "key":15, "parentId":2, "folder": false, "lazy": 
true},', <Row {'taxonomy_column_name': 'IT System', 
'taxonomy_column_parent_fk': None, 'id': 32L}>: '{"title": "IT System", 
"key":32, "parentId":2, "folder": false, "lazy": true},', <Row 
{'taxonomy_column_name': 'Federal US government', 
'taxonomy_column_parent_fk': None, 'id': 3L}>: '{"title": "Federal US 
government", "key":3, "parentId":2, "folder": false, "lazy": true},', <Row 
{'taxonomy_column_name': 'Province', 'taxonomy_column_parent_fk': 24L, 
'id': 25L}>: '{"title": "Province", "key":25, "parentId":2, "folder": 
false, "lazy": true},', <Row {'taxonomy_column_name': 'County', 
'taxonomy_column_parent_fk': 4L, 'id': 5L}>: '{"title": "County", "key":5, 
"parentId":2, "folder": false, "lazy": true},', <Row 
{'taxonomy_column_name': 'Executive Branch', 'taxonomy_column_parent_fk': 
None, 'id': 8L}>: '{"title": "Executive Branch", "key":8, "parentId":2, 
"folder": false, "lazy": true},', <Row {'taxonomy_column_name': 'Council of 
Ministers', 'taxonomy_column_parent_fk': None, 'id': 20L}>: '{"title": 
"Council of Ministers", "key":20, "parentId":2, "folder": false, "lazy": 
true},'}

Is there a python "JSON.parse" function I can use to make it valid JSON 
(https://jsonformatter.curiousconcept.com/)?

I tried this 

for r in new_roots:
       result[r] = gluon.contrib.simplejson.loads('{"title": '  +  '"' + 
r.taxonomy_column_name 
+  '"' +   ', "key":' +   str(r.id) +  ', "parentId":' + '2' + ', "folder": 
false, "lazy": true}')

but data came out encoded as below:

{<Row {'taxonomy_column_name': 'Province', 'taxonomy_column_parent_fk': 
24L, 'id': 25L}>: {u'folder': False, u'parentId': 2, u'lazy': True, u'key': 
25, u'title': u'Province'},

Tried this: 
result[r] = json.dumps({"title" + ':'   +  str(r.taxonomy_column_name) + ', 
' + "key" + ':' + str(r.id) + ', ' + "parentId" + ':' + '2' + ', ' + 
"folder" + ':' + 'false' + ', ' + "lazy" + ':' + 'true'}) 

but data resulted in: 

*<type 'exceptions.TypeError'> set(['title:Defense and National Security, 
key:16, parentId:2, folder:false, lazy:true']) is not JSON serializable*

Is it supposed to go into a dict like that?

thanks,

Alex Glaros

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to