2019-02-25 14:48:22 +01:00
|
|
|
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
|
2015-02-09 08:12:42 +01:00
|
|
|
|
|
|
|
#include "base/dictionary.hpp"
|
|
|
|
#include "base/function.hpp"
|
|
|
|
#include "base/functionwrapper.hpp"
|
|
|
|
#include "base/scriptframe.hpp"
|
|
|
|
#include "base/initialize.hpp"
|
|
|
|
#include "base/json.hpp"
|
|
|
|
|
|
|
|
using namespace icinga;
|
|
|
|
|
|
|
|
static String JsonEncodeShim(const Value& value)
|
|
|
|
{
|
|
|
|
return JsonEncode(value);
|
|
|
|
}
|
|
|
|
|
2016-08-27 09:35:08 +02:00
|
|
|
INITIALIZE_ONCE([]() {
|
2022-12-07 11:18:28 +01:00
|
|
|
Namespace::Ptr jsonNS = new Namespace(true);
|
2015-02-09 08:12:42 +01:00
|
|
|
|
2018-08-07 13:55:41 +02:00
|
|
|
/* Methods */
|
|
|
|
jsonNS->Set("encode", new Function("Json#encode", JsonEncodeShim, { "value" }, true));
|
|
|
|
jsonNS->Set("decode", new Function("Json#decode", JsonDecode, { "value" }, true));
|
|
|
|
|
2022-12-07 11:18:28 +01:00
|
|
|
jsonNS->Freeze();
|
2018-08-07 13:55:41 +02:00
|
|
|
|
|
|
|
Namespace::Ptr systemNS = ScriptGlobal::Get("System");
|
2023-01-09 16:12:59 +01:00
|
|
|
systemNS->Set("Json", jsonNS, true);
|
2016-08-27 09:35:08 +02:00
|
|
|
});
|