MCPcopy Create free account
hub / github.com/DOI-USGS/ISIS3 / pvlContainerToJSON

Function pvlContainerToJSON

isis/src/base/objs/PvlToJSON/PvlToJSON.cpp:133–167  ·  view source on GitHub ↗

* Convert the contents of a PvlContainer to a JSON object. * Any comments in the container will be stored in "Comment". * Comments associated with keywords will be stored inside their json object. * If a keyword is repeated in the container, then the instances will be * packed into an array in the order that they occur. * * This function is used by the PvlGroup, PvlObject, and Pv

Source from the content-addressed store, hash-verified

131 * @return @b json The contents of the container as a JSON object
132 */
133 json pvlContainerToJSON(PvlContainer &container) {
134 json jsonContainer;
135
136 // Convert keywords
137 PvlContainer::PvlKeywordIterator keywordIt;
138 for (keywordIt = container.begin(); keywordIt != container.end(); keywordIt++) {
139 string keywordName = keywordIt->name().replace("^", "ptr").replace(":", "_").toStdString();
140 // Handle repeated keywords by packing them into an array
141 if ( jsonContainer.contains(keywordName) ) {
142 if (!jsonContainer[keywordName].is_array()) {
143 json repeatedArray;
144 repeatedArray.push_back(jsonContainer[keywordName]);
145 jsonContainer[keywordName] = repeatedArray;
146 }
147 jsonContainer[keywordName].push_back(pvlKeywordToJSON(*keywordIt));
148 }
149 else {
150 jsonContainer[keywordName] = pvlKeywordToJSON(*keywordIt);
151 }
152 }
153
154 // Optionally convert comments
155 if (container.comments() == 1) {
156 jsonContainer["Comment"] = container.comment(0).toStdString();
157 }
158 else if (container.comments() > 1) {
159 json commentList;
160 for (int i = 0; i < container.comments(); i++) {
161 commentList.push_back(container.comment(i).toStdString());
162 }
163 jsonContainer["Comment"] = commentList;
164 }
165 return jsonContainer;
166
167 }
168
169
170 /**

Callers 2

pvlGroupToJSONFunction · 0.85
pvlObjectToJSONFunction · 0.85

Calls 9

pvlKeywordToJSONFunction · 0.85
replaceMethod · 0.80
beginMethod · 0.45
endMethod · 0.45
nameMethod · 0.45
containsMethod · 0.45
push_backMethod · 0.45
commentsMethod · 0.45
commentMethod · 0.45

Tested by

no test coverage detected