confirm_expected_subfields <- function(parsed_josn, field, expected_subfields, fail_or_warn=c("fail", "warn")) {
## In a list, such as a nested JSON, we might expect that a field have certain subfields
## This function confirms that all expected_subfields are in the names of fields

  if (isTRUE(fail_or_warn))
      fail_or_warn <- "fail"
  else
    fail_or_warn <- match.arg(fail_or_warn)
  expected_subfields %<>% sort
  actual <- names(parsed_josn[[field]]) %>% sort
  OK <- identical(actual, expected_subfields)

  if (!length(actual))
    actual <- " < No subfields found >"

  if (!OK) {
      msg <- paste0("field '", field, "' does not match to the expected subfields"
             , "\n\tEXPECTED: ", commaSep(expected_subfields)
             , "\n\tACTUAL  : ", commaSep(actual)
             )
      if (fail_or_warn == "fail")
        stop(msg, call.=FALSE)
      warning(msg, call.=FALSE)
      return(invisible(FALSE))
  }
  return(invisible(TRUE))
}
