@@ -166,6 +166,11 @@ cat("\n2: START PARSING INPUTS\n\n")
166166convertedKeys <- c()
167167
168168for (key in names(inputParameters )) {
169+ value_no_spaces <- gsub(" " , " " , inputParameters [[key ]])
170+ if (value_no_spaces == " " ) {
171+ inputParameters [[key ]] <- NULL
172+ }
173+
169174 if (is.character(inputParameters [[key ]]) &&
170175 (endsWith(inputParameters [[key ]], " .dat" ) ||
171176 endsWith(inputParameters [[key ]], " .txt" ))) {
@@ -180,7 +185,61 @@ for (key in names(inputParameters)) {
180185 inputParameters [[key ]] <- json_string
181186
182187 convertedKeys <- append(convertedKeys , key )
183- } else {
188+ } else if (
189+ grepl(" _object" , key ) &&
190+ ! is.null(inputParameters [[key ]]) &&
191+ ! is.na(inputParameters [[key ]]) &&
192+ gsub(" " , " " , inputParameters [[key ]]) != " "
193+ ) {
194+ decoded_value <- gsub(" __oc__" , " {" , inputParameters [[key ]])
195+ decoded_value <- gsub(" __cc__" , " }" , decoded_value )
196+ decoded_value <- gsub(" __ob__" , " [" , decoded_value )
197+ decoded_value <- gsub(" __cb__" , " ]" , decoded_value )
198+ decoded_value <- gsub(" __dq__" , " \" " , decoded_value ) # Optional: sometimes used for quotes
199+ decoded_value <- gsub(" __cn__" , " :" , decoded_value ) # Optional: used for colon in older versions
200+
201+ parsed_json <- fromJSON(decoded_value )
202+ convertedKey <- gsub(" _object" , " " , key )
203+ convertedKeys <- append(convertedKeys , convertedKey )
204+ # json_string <- toJSON(parsed_json, auto_unbox = FALSE)
205+ inputParameters [[key ]] <- parsed_json
206+ } else if (grepl(" _array" , key )) {
207+ keyParts <- strsplit(key , split = " _" )[[1 ]]
208+ type <- keyParts [length(keyParts )]
209+ values <- inputParameters [[key ]]
210+ if (is.character(values ) && grepl(" ," , values )) {
211+ value_list <- unlist(strsplit(values , split = " ," ))
212+ } else if (is.character(values )) {
213+ value_list <- c(values )
214+ }
215+
216+ convertedValues <- c()
217+
218+ for (value in value_list ) {
219+ value <- as.character(value )
220+ value <- gsub(" " , " " , value )
221+ # if(type == "integer") {
222+ # value <- as.integer(value)
223+ # } else if (type == "numeric") {
224+ # value <- as.numeric(balue)
225+ # } else if (type == "character") {
226+ # value <- as.character(value)
227+ # value <- gsub(" ", "", value)
228+ # }
229+ convertedValues <- append(convertedValues , value )
230+ convertedKey <- " "
231+ for (part in keyParts ) {
232+ if (part == " array" ) {
233+ break
234+ }
235+ convertedKey <- paste(convertedKey , paste(part , " _" , sep = " " ), sep = " " )
236+ }
237+ convertedKey <- substr(convertedKey , 1 , nchar(convertedKey )- 1 )
238+ }
239+ inputParameters [[key ]] <- convertedValues
240+ convertedKeys <- append(convertedKeys , convertedKey )
241+ }
242+ else {
184243 if (! is.null(inputParameters [[key ]])) {
185244 convertedKeys <- append(convertedKeys , key )
186245 }
0 commit comments