Skip to content
Snippets Groups Projects
Commit e1c8ed47 authored by Botond Baranyi's avatar Botond Baranyi
Browse files

Added JSON functions


Signed-off-by: default avatarBotond Baranyi <botond.baranyi@ericsson.com>
parent fa740d8a
No related branches found
No related tags found
1 merge request!1Added JSON functions
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2018 Ericsson
The copyright to the computer program(s) herein is the property of Ericsson.
The program(s) may be used and/or copied only with the written permission
of Ericsson or in accordance with the terms and conditions stipulated in the
agreement/contract under which the program(s) has been supplied.
File: TCCUsefulFunctions_CNL113472_JSON.tpd
Description: tpd project file
Rev: R36B
Prodnr: CNL 113 472
-->
<TITAN_Project_File_Information version="1.0">
<ProjectName>TCCUsefulFunctions_CNL113472_JSON</ProjectName>
<Files>
<FileResource projectRelativePath="TCC_JSON.cc" relativeURI="src/TCC_JSON.cc"/>
<FileResource projectRelativePath="json.hpp" relativeURI="src/json.hpp"/>
<FileResource projectRelativePath="TCC_JSON_Functions.ttcn" relativeURI="src/TCC_JSON_Functions.ttcn"/>
<!-- <FileResource projectRelativePath="TCC_JSON_Example.ttcn" relativeURI="demo/TCC_JSON_Example.ttcn"/> -->
<!-- <FileResource projectRelativePath="TCC_JSON_Example.cfg" relativeURI="demo/TCC_JSON_Example.cfg"/> -->
</Files>
<ActiveConfiguration>Default</ActiveConfiguration>
<Configurations>
<Configuration name="Default">
<ProjectProperties>
<MakefileSettings>
<generateInternalMakefile>true</generateInternalMakefile>
<GNUMake>true</GNUMake>
<incrementalDependencyRefresh>true</incrementalDependencyRefresh>
<targetExecutable>bin/TCCUsefulFunctions_CNL113472_JSON</targetExecutable>
<otherOptimizationFlags>-std=c++11</otherOptimizationFlags>
<buildLevel>Level 3 - Creating object files with dependency update</buildLevel>
</MakefileSettings>
<LocalBuildSettings>
<workingDirectory>bin</workingDirectory>
</LocalBuildSettings>
</ProjectProperties>
</Configuration>
</Configurations>
</TITAN_Project_File_Information>
##############################################################################
#
# Copyright (c) 2000-2018 Ericsson Telecom AB
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v2.0
# which accompanies this distribution, and is available at
# https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
##############################################################################
#
# File: TCC_JSON_Example.ttcn
# Description: TCC Useful Functions: JSON Functions
# Rev: R36B
# Prodnr: CNL 113 472
#
##############################################################################
[MODULE_PARAMETERS]
JSON_PRETTY_PRINTING := 1;
JSON_INDENT_CHAR := "\t";
JSON_ENSURE_ASCII := true;
[LOGGING]
Logfile := "TCC_JSON_Example_%r.log"
FileMask := LOG_ALL
ConsoleMask := TTCN_WARNING | TTCN_ERROR | TTCN_TESTCASE | TTCN_STATISTICS
[EXECUTE]
TCC_JSON_Example
///////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2000-2018 Ericsson Telecom AB
//
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v2.0
// which accompanies this distribution, and is available at
// https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
///////////////////////////////////////////////////////////////////////////////
//
// File: TCC_JSON_Example.ttcn
// Description: TCC Useful Functions: JSON Functions
// Rev: R36B
// Prodnr: CNL 113 472
//
///////////////////////////////////////////////////////////////////////////////
module TCC_JSON_Example {
import from TCC_JSON_Functions all;
control {
var universal charstring x1 := "{ \"a\" : 1, \"b\" : \"abc\", \"c\" : [ -1, 0.6, null, false ] }";
log("JSON value: ", x1);
log("--------------------------------------------------");
var octetstring mp1 := JSON_to_MessagePack(x1);
log("To MessagePack: ", mp1);
log("From MessagePack: ", MessagePack_to_JSON(mp1));
var octetstring mp2 := '82A7'O & char2oct("compact") & 'C3A6'O & char2oct("schema") & '00'O;
log("From MessagePack (", mp2, "): ", MessagePack_to_JSON(mp2));
var octetstring mp3 := '81A161A40110C591'O;
log("From MessagePack (", mp3, "): ", MessagePack_to_JSON(mp3));
log("--------------------------------------------------");
var octetstring ubj1 := JSON_to_UBJSON(x1);
var octetstring ubj2 := JSON_to_UBJSON(x1, true);
var octetstring ubj3 := JSON_to_UBJSON(x1, true, true);
log("To UBJSON (basic): ", ubj1);
log("To UBJSON (use size): ", ubj2);
log("To UBJSON (use size and type): ", ubj3);
log("From UBJSON (1st value): ", UBJSON_to_JSON(ubj1));
log("From UBJSON (2nd value): ", UBJSON_to_JSON(ubj2));
log("From UBJSON (3rd value): ", UBJSON_to_JSON(ubj3));
log("--------------------------------------------------");
var octetstring cb := JSON_to_CBOR(x1);
log("To CBOR: ", cb);
log("From CBOR: ", CBOR_to_JSON(cb));
log("--------------------------------------------------");
var universal charstring x2 := flatten_JSON(x1);
log("Flattened: ", x2);
log("Unflattened: ", unflatten_JSON(x2));
}
} // end of module
///////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2000-2018 Ericsson Telecom AB
//
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v2.0
// which accompanies this distribution, and is available at
// https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
///////////////////////////////////////////////////////////////////////////////
//
// File: TCC_JSON.cc
// Description: TCC Useful Functions: JSON Functions
// Rev: R36B
// Prodnr: CNL 113 472
//
///////////////////////////////////////////////////////////////////////////////
#include "TCC_JSON_Functions.hh"
#include "json.hpp"
#include <vector>
using nlohmann::json;
using nlohmann::detail::input_adapter;
namespace TCC__JSON__Functions {
///////////////////////////////////////////////////////////////////////////////
//
// Function: from_unichar
//
// Description:
// Helper function. Creates a JSON object from a TTCN-3 universal charstring.
// Multi-byte characters are converted into UTF-8 format.
//
///////////////////////////////////////////////////////////////////////////////
json from_unichar(const UNIVERSAL_CHARSTRING& ustr)
{
TTCN_Buffer buff;
ustr.encode_utf8(buff);
return json::parse(input_adapter(buff.get_data(), buff.get_len()));
}
///////////////////////////////////////////////////////////////////////////////
//
// Function: to_unichar
//
// Description:
// Helper function. Converts a JSON object to a TTCN-3 universal charstring.
// The strings in the JSON object are treated as if they were in UTF-8 format.
// The output format of the JSON document is determined by the module parameters
// JSON__PRETTY__PRINTING, JSON__INDENT__CHAR and JSON__ENSURE__ASCII.
//
///////////////////////////////////////////////////////////////////////////////
UNIVERSAL_CHARSTRING to_unichar(const json& j)
{
const std::string& j_str = j.dump(JSON__PRETTY__PRINTING,
JSON__INDENT__CHAR[0].get_char(), JSON__ENSURE__ASCII);
UNIVERSAL_CHARSTRING ret_val;
ret_val.decode_utf8(j_str.size(), reinterpret_cast<const unsigned char*>(j_str.c_str()));
return ret_val;
}
///////////////////////////////////////////////////////////////////////////////
// Function: JSON__to__CBOR
//
// Purpose:
// Converts JSON to CBOR.
//
// Parameters:
// pl__json__str - *in* *universal charstring* - JSON document
//
// Return Value:
// octetstring - resulting CBOR data
//
// Errors:
// A dynamic test case error is produced if the first parameter does not
// contain a valid JSON document.
//
// Detailed description:
// The JSON document is first converted to UTF-8 format.
// This string is converted to CBOR using the C++ JSON module.
//
///////////////////////////////////////////////////////////////////////////////
OCTETSTRING JSON__to__CBOR(const UNIVERSAL_CHARSTRING& pl__json__str)
{
try {
json j = from_unichar(pl__json__str);
const std::vector<uint8_t>& cbor_bytes = json::to_cbor(j);
return OCTETSTRING(cbor_bytes.size(), cbor_bytes.data());
}
catch (const nlohmann::detail::exception& e) {
TTCN_error("While converting JSON to CBOR: %s", e.what());
}
}
///////////////////////////////////////////////////////////////////////////////
// Function: CBOR__to__JSON
//
// Purpose:
// Converts CBOR to JSON.
//
// Parameters:
// pl__json__str - *in* *octetstring* - CBOR data
//
// Return Value:
// universal charstring - resulting JSON document
//
// Errors:
// A dynamic test case error is produced if the first parameter does not
// contain valid CBOR data (multi-octet characters must be in UTF-8 format).
//
// Detailed description:
// The CBOR data is first converted to a JSON document in UTF-8 format using
// the C++ JSON module. This conversion is affected by the module parameters
// JSON__PRETTY__PRINTING, JSON__INDENT__CHAR and JSON__ENSURE__ASCII.
// The JSON document is then converted to a universal charstring.
//
///////////////////////////////////////////////////////////////////////////////
UNIVERSAL_CHARSTRING CBOR__to__JSON(const OCTETSTRING& pl__cbor__str)
{
try {
json j = json::from_cbor(input_adapter(
static_cast<const unsigned char*>(pl__cbor__str), pl__cbor__str.lengthof()));
return to_unichar(j);
}
catch (const nlohmann::detail::exception& e) {
TTCN_error("While converting CBOR to JSON: %s", e.what());
}
}
///////////////////////////////////////////////////////////////////////////////
// Function: JSON__to__MessagePack
//
// Purpose:
// Converts JSON to MessagePack.
//
// Parameters:
// pl__json__str - *in* *universal charstring* - JSON document
//
// Return Value:
// octetstring - resulting MessagePack data
//
// Errors:
// A dynamic test case error is produced if the first parameter does not
// contain a valid JSON document.
//
// Detailed description:
// The JSON document is first converted to UTF-8 format.
// This string is converted to MessagePack using the C++ JSON module.
//
///////////////////////////////////////////////////////////////////////////////
OCTETSTRING JSON__to__MessagePack(const UNIVERSAL_CHARSTRING& pl__json__str)
{
try {
json j = from_unichar(pl__json__str);
const std::vector<uint8_t>& msgpack_bytes = json::to_msgpack(j);
return OCTETSTRING(msgpack_bytes.size(), msgpack_bytes.data());
}
catch (const nlohmann::detail::exception& e) {
TTCN_error("While converting JSON to MessagePack: %s", e.what());
}
}
///////////////////////////////////////////////////////////////////////////////
// Function: MessagePack__to__JSON
//
// Purpose:
// Converts MessagePack to JSON.
//
// Parameters:
// pl__json__str - *in* *octetstring* - MessagePack data
//
// Return Value:
// universal charstring - resulting JSON document
//
// Errors:
// A dynamic test case error is produced if the first parameter does not
// contain valid MessagePack data (multi-octet characters must be in UTF-8 format).
//
// Detailed description:
// The MessagePack data is first converted to a JSON document in UTF-8 format using
// the C++ JSON module. This conversion is affected by the module parameters
// JSON__PRETTY__PRINTING, JSON__INDENT__CHAR and JSON__ENSURE__ASCII.
// The JSON document is then converted to a universal charstring.
//
///////////////////////////////////////////////////////////////////////////////
UNIVERSAL_CHARSTRING MessagePack__to__JSON(const OCTETSTRING& pl__msgpack__str)
{
try {
json j = json::from_msgpack(input_adapter(
static_cast<const unsigned char*>(pl__msgpack__str), pl__msgpack__str.lengthof()));
return to_unichar(j);
}
catch (const nlohmann::detail::exception& e) {
TTCN_error("While converting MessagePack to JSON: %s", e.what());
}
}
///////////////////////////////////////////////////////////////////////////////
// Function: JSON__to__UBJSON
//
// Purpose:
// Converts JSON to UBJSON.
//
// Parameters:
// pl__json__str - *in* *universal charstring* - JSON document
// pl__use__size - *in* *boolean* - use size annotations for array and object types
// (default: false)
// pl__use__type - *in* *boolean* - use type annotations for array and object types
// (can only be true if pl_use_size is also true,
// default: false)
//
// Return Value:
// octetstring - resulting UBJSON data
//
// Errors:
// A dynamic test case error is produced if the first parameter does not contain
// a valid JSON document, or if pl_use_type is true, but pl_use_size is false.
//
// Detailed description:
// The JSON document is first converted to UTF-8 format.
// This string is converted to UBJSON using the C++ JSON module, with the
// size and type annotation settings specified in the parameters.
//
///////////////////////////////////////////////////////////////////////////////
OCTETSTRING JSON__to__UBJSON(const UNIVERSAL_CHARSTRING& pl__json__str,
const BOOLEAN& pl_use_size /* := false */,
const BOOLEAN& pl_use_type /* := false */)
{
if (pl_use_type && !pl_use_size) {
TTCN_error("Invalid arguments for function JSON_to_UBJSON: "
"'pl_use_type' can only be set to true if 'pl_use_size' is also true.");
}
try {
json j = from_unichar(pl__json__str);
const std::vector<uint8_t>& ubjson_bytes = json::to_ubjson(j, pl_use_size, pl_use_type);
return OCTETSTRING(ubjson_bytes.size(), ubjson_bytes.data());
}
catch (const nlohmann::detail::exception& e) {
TTCN_error("While converting JSON to UBJSON: %s", e.what());
}
}
///////////////////////////////////////////////////////////////////////////////
// Function: UBJSON__to__JSON
//
// Purpose:
// Converts UBJSON to JSON.
//
// Parameters:
// pl__json__str - *in* *octetstring* - UBJSON data
//
// Return Value:
// universal charstring - resulting JSON document
//
// Errors:
// A dynamic test case error is produced if the first parameter does not
// contain valid UBJSON data (multi-octet characters must be in UTF-8 format).
//
// Detailed description:
// The UBJSON data is first converted to a JSON document in UTF-8 format using
// the C++ JSON module. This conversion is affected by the module parameters
// JSON__PRETTY__PRINTING, JSON__INDENT__CHAR and JSON__ENSURE__ASCII.
// The JSON document is then converted to a universal charstring.
//
///////////////////////////////////////////////////////////////////////////////
UNIVERSAL_CHARSTRING UBJSON__to__JSON(const OCTETSTRING& pl__ubjson__str)
{
try {
json j = json::from_ubjson(input_adapter(
static_cast<const unsigned char*>(pl__ubjson__str), pl__ubjson__str.lengthof()));
return to_unichar(j);
}
catch (const nlohmann::detail::exception& e) {
TTCN_error("While converting UBJSON to JSON: %s", e.what());
}
}
///////////////////////////////////////////////////////////////////////////////
// Function: flatten__JSON
//
// Purpose:
// Flattens a JSON document.
//
// Parameters:
// pl__json__str - *in* *universal charstring* - input JSON document
//
// Return Value:
// universal charstring - flattened JSON document
//
// Errors:
// A dynamic test case error is produced if the first parameter does not
// contain a valid JSON document.
//
// Detailed description:
// The JSON document is first converted to UTF-8 format.
// This string is flattened using the C++ JSON module.
// The format of the flattened string is determined by the module parameters
// JSON__PRETTY__PRINTING, JSON__INDENT__CHAR and JSON__ENSURE__ASCII.
// The JSON document is then converted back to a universal charstring.
//
///////////////////////////////////////////////////////////////////////////////
UNIVERSAL_CHARSTRING flatten__JSON(const UNIVERSAL_CHARSTRING& pl__json__str)
{
try {
json j_orig = from_unichar(pl__json__str);
json j_flattened = j_orig.flatten();
return to_unichar(j_flattened);
}
catch (const nlohmann::detail::exception& e) {
TTCN_error("While flattening JSON value: %s", e.what());
}
}
///////////////////////////////////////////////////////////////////////////////
// Function: unflatten__JSON
//
// Purpose:
// Flattens a JSON document.
//
// Parameters:
// pl__json__str - *in* *universal charstring* - flattened JSON document
//
// Return Value:
// universal charstring - unflattened JSON document
//
// Errors:
// A dynamic test case error is produced if the first parameter does not
// contain a valid and flattened JSON document.
//
// Detailed description:
// The JSON document is first converted to UTF-8 format.
// This string is unflattened using the C++ JSON module.
// The format of the unflattened string is determined by the module parameters
// JSON__PRETTY__PRINTING, JSON__INDENT__CHAR and JSON__ENSURE__ASCII.
// The JSON document is then converted back to a universal charstring.
//
///////////////////////////////////////////////////////////////////////////////
UNIVERSAL_CHARSTRING unflatten__JSON(const UNIVERSAL_CHARSTRING& pl__json__str)
{
try {
json j_orig = from_unichar(pl__json__str);
json j_unflattened = j_orig.unflatten();
return to_unichar(j_unflattened);
}
catch (const nlohmann::detail::exception& e) {
TTCN_error("While unflattening JSON value: %s", e.what());
}
}
} // end of namespace
///////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2000-2018 Ericsson Telecom AB
//
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v2.0
// which accompanies this distribution, and is available at
// https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
///////////////////////////////////////////////////////////////////////////////
//
// File: TCC_JSON_Functions.ttcn
// Description: TCC Useful Functions: JSON Functions
// Rev: R36B
// Prodnr: CNL 113 472
//
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Module: TCC_JSON_Functions
//
// Purpose:
// This module supports manipulation of JSON documents
//
// Module Parameters:
// The following module parameters affect the return values of all functions
// in this module that return a JSON document.
//
// JSON_PRETTY_PRINTING - integer - Indicates whether to use pretty or
// compact printing, and how many indenting
// characters should be added in case of
// pretty printing.
// -1 means compact printing (default),
// 0 or greater means pretty printing.
//
// JSON_INDENT_CHAR - charstring - Sets the indenting character used if
// pretty printing is set.
// Must contain a single character.
// Default: " "
//
// JSON_ENSURE_ASCII - boolean - Ensures that the JSON document only contains
// ASCII characters. Non-ASCII characters in
// JSON strings are escaped using the '\uHHHH'
// notation. (Not set by default.)
//
// Module depends on:
// JSON for Modern C++ (version 3.1.2), https://github.com/nlohmann/json
//
// Note: Due to this dependency any projects using this module must be built
// with C++11 or newer (e.g.: g++ compiler option '-std=c++11').
//
///////////////////////////////////////////////////////////////////////////////
module TCC_JSON_Functions {
type charstring IndentChar length (1);
modulepar integer JSON_PRETTY_PRINTING := -1;
modulepar IndentChar JSON_INDENT_CHAR := " ";
modulepar boolean JSON_ENSURE_ASCII := false;
///////////////////////////////////////////////////////////////////////////////
// Function: JSON_to_CBOR
//
// Purpose:
// Converts JSON to CBOR.
//
// Parameters:
// pl_json_str - *in* *universal charstring* - JSON document
//
// Return Value:
// octetstring - resulting CBOR data
//
// Errors:
// A dynamic test case error is produced if the first parameter does not
// contain a valid JSON document.
//
// Detailed description:
// The JSON document is first converted to UTF-8 format.
// This string is converted to CBOR using the C++ JSON module.
//
///////////////////////////////////////////////////////////////////////////////
external function JSON_to_CBOR(in universal charstring pl_json_str) return octetstring
///////////////////////////////////////////////////////////////////////////////
// Function: CBOR_to_JSON
//
// Purpose:
// Converts CBOR to JSON.
//
// Parameters:
// pl_json_str - *in* *octetstring* - CBOR data
//
// Return Value:
// universal charstring - resulting JSON document
//
// Errors:
// A dynamic test case error is produced if the first parameter does not
// contain valid CBOR data (multi-octet characters must be in UTF-8 format).
//
// Detailed description:
// The CBOR data is first converted to a JSON document in UTF-8 format using
// the C++ JSON module. This conversion is affected by the module parameters
// JSON_PRETTY_PRINTING, JSON_INDENT_CHAR and JSON_ENSURE_ASCII.
// The JSON document is then converted to a universal charstring.
//
///////////////////////////////////////////////////////////////////////////////
external function CBOR_to_JSON(in octetstring pl_cbor_str) return universal charstring
///////////////////////////////////////////////////////////////////////////////
// Function: JSON_to_MessagePack
//
// Purpose:
// Converts JSON to MessagePack.
//
// Parameters:
// pl_json_str - *in* *universal charstring* - JSON document
//
// Return Value:
// octetstring - resulting MessagePack data
//
// Errors:
// A dynamic test case error is produced if the first parameter does not
// contain a valid JSON document.
//
// Detailed description:
// The JSON document is first converted to UTF-8 format.
// This string is converted to MessagePack using the C++ JSON module.
//
///////////////////////////////////////////////////////////////////////////////
external function JSON_to_MessagePack(in universal charstring pl_json_str) return octetstring
///////////////////////////////////////////////////////////////////////////////
// Function: MessagePack_to_JSON
//
// Purpose:
// Converts MessagePack to JSON.
//
// Parameters:
// pl_json_str - *in* *octetstring* - MessagePack data
//
// Return Value:
// universal charstring - resulting JSON document
//
// Errors:
// A dynamic test case error is produced if the first parameter does not
// contain valid MessagePack data (multi-octet characters must be in UTF-8 format).
//
// Detailed description:
// The MessagePack data is first converted to a JSON document in UTF-8 format using
// the C++ JSON module. This conversion is affected by the module parameters
// JSON_PRETTY_PRINTING, JSON_INDENT_CHAR and JSON_ENSURE_ASCII.
// The JSON document is then converted to a universal charstring.
//
///////////////////////////////////////////////////////////////////////////////
external function MessagePack_to_JSON(in octetstring pl_msgpack_str) return universal charstring
///////////////////////////////////////////////////////////////////////////////
// Function: JSON_to_UBJSON
//
// Purpose:
// Converts JSON to UBJSON.
//
// Parameters:
// pl_json_str - *in* *universal charstring* - JSON document
// pl_use_size - *in* *boolean* - use size annotations for array and object types
// (default: false)
// pl_use_type - *in* *boolean* - use type annotations for array and object types
// (can only be true if pl_use_size is also true,
// default: false)
//
// Return Value:
// octetstring - resulting UBJSON data
//
// Errors:
// A dynamic test case error is produced if the first parameter does not contain
// a valid JSON document, or if pl_use_type is true, but pl_use_size is false.
//
// Detailed description:
// The JSON document is first converted to UTF-8 format.
// This string is converted to UBJSON using the C++ JSON module, with the
// size and type annotation settings specified in the parameters.
//
///////////////////////////////////////////////////////////////////////////////
external function JSON_to_UBJSON(in universal charstring pl_json_str,
in boolean pl_use_size := false,
in boolean pl_use_type := false) return octetstring
///////////////////////////////////////////////////////////////////////////////
// Function: UBJSON_to_JSON
//
// Purpose:
// Converts UBJSON to JSON.
//
// Parameters:
// pl_json_str - *in* *octetstring* - UBJSON data
//
// Return Value:
// universal charstring - resulting JSON document
//
// Errors:
// A dynamic test case error is produced if the first parameter does not
// contain valid UBJSON data (multi-octet characters must be in UTF-8 format).
//
// Detailed description:
// The UBJSON data is first converted to a JSON document in UTF-8 format using
// the C++ JSON module. This conversion is affected by the module parameters
// JSON_PRETTY_PRINTING, JSON_INDENT_CHAR and JSON_ENSURE_ASCII.
// The JSON document is then converted to a universal charstring.
//
///////////////////////////////////////////////////////////////////////////////
external function UBJSON_to_JSON(in octetstring pl_ubjson_str) return universal charstring
///////////////////////////////////////////////////////////////////////////////
// Function: flatten_JSON
//
// Purpose:
// Flattens a JSON document.
//
// Parameters:
// pl_json_str - *in* *universal charstring* - input JSON document
//
// Return Value:
// universal charstring - flattened JSON document
//
// Errors:
// A dynamic test case error is produced if the first parameter does not
// contain a valid JSON document.
//
// Detailed description:
// The JSON document is first converted to UTF-8 format.
// This string is flattened using the C++ JSON module.
// The format of the flattened string is determined by the module parameters
// JSON_PRETTY_PRINTING, JSON_INDENT_CHAR and JSON_ENSURE_ASCII.
// The JSON document is then converted back to a universal charstring.
//
///////////////////////////////////////////////////////////////////////////////
external function flatten_JSON(in universal charstring pl_json_str) return universal charstring
///////////////////////////////////////////////////////////////////////////////
// Function: unflatten_JSON
//
// Purpose:
// Flattens a JSON document.
//
// Parameters:
// pl_json_str - *in* *universal charstring* - flattened JSON document
//
// Return Value:
// universal charstring - unflattened JSON document
//
// Errors:
// A dynamic test case error is produced if the first parameter does not
// contain a valid and flattened JSON document.
//
// Detailed description:
// The JSON document is first converted to UTF-8 format.
// This string is unflattened using the C++ JSON module.
// The format of the unflattened string is determined by the module parameters
// JSON_PRETTY_PRINTING, JSON_INDENT_CHAR and JSON_ENSURE_ASCII.
// The JSON document is then converted back to a universal charstring.
//
///////////////////////////////////////////////////////////////////////////////
external function unflatten_JSON(in universal charstring pl_json_str) return universal charstring
}
src/json.hpp 0 → 100644
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment