Hi, I use Send HTTP Request (Workflow). The server response is in XML. How can I convert XML to JSON? Thank you
XML to JSON
Collapse
X
-
-
You just need a custom formula function that will convert the xml to json, try this below:
1 - Create a file custom/Espo/Custom/Core/Formula/Functions/JsonGroup/ConvertXmlToJsonType.php with the code:
Code:<?php namespace Espo\Custom\Core\Formula\Functions\JsonGroup; use Espo\Core\Formula\Functions\BaseFunction; use Espo\Core\Formula\ArgumentList; class ConvertXmlToJsonType extends BaseFunction { public function process(ArgumentList $args) { $args = $this->evaluate($args); if (count($args) < 1) { $this->throwTooFewArguments(); }; $xml = $args[0]; // Load xml data into xml data object $xmldata = simplexml_load_string($xml); // Encode this xml data into json using json_encode function $jsondata = json_encode($xmldata); return $jsondata; } }
Code:{ "functionList": [ "__APPEND__", { "name": "xml\\convertToJson", "insertText": "xml\\convertToJson(VALUE)" } ], "functionClassNameMap": { "xml\\convertToJson": "Espo\\Custom\\Core\\Formula\\Functions\\JsonGroup\\ConvertXmlToJsonType" } }
Good luckRabii
Web DevComment
Comment