Answer the question
In order to leave comments, you need to log in
How to pass a vk api keyboard JSON object as a string?
Keyboards for chatbots have become available on VKontakte. The documentation says that "Keyboard JSON object is passed as a string"
Here is an example of a keyboard in JSON
// клавиатура вида
// | Red | Green |
// | White | Blue |
{
// ...другие поля объекта Message
keyboard: {
"one_time": false,
"buttons": [
[{
"action": {
"type": "text",
"payload": "{\"button\": \"1\"}",
"label": "Red"
},
"color": "negative"
},
{
"action": {
"type": "text",
"payload": "{\"button\": \"2\"}",
"label": "Green"
},
"color": "positive"
}],
[{
"action": {
"type": "text",
"payload": "{\"button\": \"3\"}",
"label": "White"
},
"color": "default"
},
{
"action": {
"type": "text",
"payload": "{\"button\": \"4\"}",
"label": "Blue"
},
"color": "primary"
}]
]
}
}
Answer the question
In order to leave comments, you need to log in
import json
data = {'jsonKey': None}
json.dumps(data)
>>> '{"jsonKey": null}'
json.loads(json.dumps(data))
>>> {u'jsonKey': None}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question