June 2018 by Dave Winer

XML-RPC-in-JSON examples

My new JavaScript toolkit for XML-RPC supports a JSON syntax.

Here's a table comparing the two versions.

Single param

<methodCall>
	<methodName>examples.getStateName</methodName>
	<params>
		<param>
			<value><int>50</int></value>
			</param>
		</params>
	</methodCall>
{
	"methodCall": {
		"methodName": "examples.getStateName",
		"params": [
			23
			]
		}
	}

Param is an array

<methodCall>
	<methodName>examples.getStateList</methodName>
	<params>
		<param>
			<value>
				<array>
					<data>
						<value><int>12</int></value>
						<value><int>44</int></value>
						<value><int>4</int></value>
						<value><int>1</int></value>
						</data>
					</array>
				</value>
			</param>
		</params>
	</methodCall>
{
	"methodCall": {
		"methodName": "examples.getStateList",
		"params": [
			[
				12,
				44,
				4
				]
			]
		}
	}

Param is a struct

<methodCall>
	<methodName>examples.getStateStruct</methodName>
	<params>
		<param>
			<value>
				<struct>
					<member>
						<name>state1</name>
						<value>
							<int>12</int>
							</value>
						</member>
					<member>
						<name>state2</name>
						<value>
							<int>8</int>
							</value>
						</member>
					</struct>
				</value>
			</param>
		</params>
	</methodCall>
{
	"methodCall": {
		"methodName": "examples.getStateStruct",
		"params": [
			{
				"state1": 12,
				"state2": 8
				}
			]
		}
	}

Normal, non-error response

<methodResponse>
	<params>
		<param>
			<value>
				<string>South Carolina</string>
				</value>
			</param>
		</params>
	</methodResponse>
{
	"methodResponse": {
		"value": "South Carolina"
		}
	}

Error response

<methodResponse>
	<fault>
		<value>
			<struct>
				<member>
					<name>faultCode</name>
					<value><i4>1</i4></value>
					</member>
				<member>
					<name>faultString</name>
					<value><string>Can't delete the file because it doesn't exist.</string></value>
					</member>
				</struct>
			</value>
		</fault>
	</methodResponse>
{
	"methodResponse": {
		"fault": {
			"faultCode": 1,
			"faultString": "Can't delete the file because it doesn't exist."
			}
		}
	}