9 #include <nlohmann/json.hpp>
12 #include "PvlKeyword.h"
14 using json = nlohmann::json;
81 if (keyword.
size() == 1) {
82 jsonKeyword[
"Value"] = keyword[0].toStdString();
84 else if (keyword.
size() > 1) {
86 for (
int i = 0; i < keyword.
size(); i++) {
87 valueList.push_back(keyword[i].toStdString());
89 jsonKeyword[
"Value"] = valueList;
93 if (keyword.
size() == 1 && !keyword.
unit(0).isEmpty()) {
94 jsonKeyword[
"Units"] = keyword.
unit(0).toStdString();
96 else if (keyword.
size() > 1 && !keyword.
unit(0).isEmpty()) {
98 for (
int i = 0; i < keyword.
size(); i++) {
99 valueList.push_back(keyword.
unit(i).toStdString());
101 jsonKeyword[
"Units"] = valueList;
106 jsonKeyword[
"Comment"] = keyword.
comment(0).toStdString();
110 for (
int i = 0; i < keyword.
comments(); i++) {
111 commentList.push_back(keyword.
comment(i).toStdString());
113 jsonKeyword[
"Comment"] = commentList;
137 for (keywordIt = container.
begin(); keywordIt != container.
end(); keywordIt++) {
139 if ( jsonContainer.contains(keywordIt->name().toStdString()) ) {
140 if (!jsonContainer[keywordIt->name().toStdString()].is_array()) {
142 repeatedArray.push_back(jsonContainer[keywordIt->name().toStdString()]);
143 jsonContainer[keywordIt->name().toStdString()] = repeatedArray;
145 jsonContainer[keywordIt->name().toStdString()].push_back(
pvlKeywordToJSON(*keywordIt));
148 jsonContainer[keywordIt->name().toStdString()] =
pvlKeywordToJSON(*keywordIt);
153 if (container.comments() == 1) {
154 jsonContainer[
"Comment"] = container.comment(0).toStdString();
156 else if (container.comments() > 1) {
158 for (
int i = 0; i < container.comments(); i++) {
159 commentList.push_back(container.comment(i).toStdString());
161 jsonContainer[
"Comment"] = commentList;
163 return jsonContainer;
300 for (groupIt =
object.beginGroup(); groupIt !=
object.endGroup(); groupIt++) {
302 if ( jsonObject.contains(groupIt->name().toStdString()) ) {
303 if (!jsonObject[groupIt->name().toStdString()].is_array()) {
305 repeatedArray.push_back(jsonObject[groupIt->name().toStdString()]);
306 jsonObject[groupIt->name().toStdString()] = repeatedArray;
308 jsonObject[groupIt->name().toStdString()].push_back(
pvlGroupToJSON(*groupIt));
311 jsonObject[groupIt->name().toStdString()] =
pvlGroupToJSON(*groupIt);
317 for (objectIt =
object.beginObject(); objectIt !=
object.endObject(); objectIt++) {
319 if ( jsonObject.contains(objectIt->name().toStdString()) ) {
320 if (!jsonObject[objectIt->name().toStdString()].is_array()) {
322 repeatedArray.push_back(jsonObject[objectIt->name().toStdString()]);
323 jsonObject[objectIt->name().toStdString()] = repeatedArray;
325 jsonObject[objectIt->name().toStdString()].push_back(
pvlObjectToJSON(*objectIt));
328 jsonObject[objectIt->name().toStdString()] =
pvlObjectToJSON(*objectIt);