# HG changeset patch # User Kim Alvefur # Date 1640815963 -3600 # Node ID 8d4b91a703afe0c89250de8594979e938e89ed41 # Parent f69c5a443156ea3c2c92e2b0386a6dbf499d2fb9 mod_pubsub_post: Document JSON to XML mapping capability diff -r f69c5a443156 -r 8d4b91a703af mod_pubsub_post/README.markdown --- a/mod_pubsub_post/README.markdown Wed Dec 29 19:40:28 2021 +0100 +++ b/mod_pubsub_post/README.markdown Wed Dec 29 23:12:43 2021 +0100 @@ -106,3 +106,54 @@ pubsub:create("princely_musings", true); pubsub:set_affiliation("princely_musings", true, "127.0.0.1", "publisher"); ``` + +## Data mappings + +The datamapper library added in trunk allows posting JSON and having it +converted to XML based on a special JSON Schema. + +``` json +{ + "properties" : { + "content" : { + "type" : "string" + }, + "title" : { + "type" : "string" + } + }, + "type" : "object", + "xml" : { + "name" : "musings", + "namespace" : "urn:example:princely" + } +} +``` + +And in the Prosody config file: + +``` lua +pubsub_post_mappings = { + princely_musings = "musings.json"; +} +``` + +Then, POSTing a JSON payload like + +``` json +{ + "content" : "To be, or not to be: that is the question", + "title" : "Soliloquy" +} +``` + +results in a payload like + +``` xml + + Soliloquy + To be, or not to be: that is the question + +``` + +being published to the node.