code: private void beforeValue(boolean root) throws IOException {
          switch (peek()) {
              case EMPTY_DOCUMENT: // first in document
                  if (!lenient && !root) {
                      throw new IllegalStateException(
                              "JSON must start with an array or an object.");
                  }
                  replaceTop(JsonScope.NONEMPTY_DOCUMENT);
                  break;
  
              case EMPTY_ARRAY: // first in array
                  replaceTop(JsonScope.NONEMPTY_ARRAY);
                  newline();
                  break;
  
              case NONEMPTY_ARRAY: // another in array
                  out.append(',');
                  newline();
                  break;
  
              case DANGLING_NAME: // value for name
                  out.append(separator);
                  replaceTop(JsonScope.NONEMPTY_OBJECT);
                  break;
  
              case NONEMPTY_DOCUMENT:
                  throw new IllegalStateException(
                          "JSON must have only one top-level value.");
  
              default:
                  throw new IllegalStateException("Nesting problem: " + stack);
          }
      }
docs: Inserts any necessary separators and whitespace before a literal value,
  inline array, or inline object. Also adjusts the stack to expect either a
  closing bracket or another element.
  
  @param root true if the value is a new array or object, the two values
  permitted as top-level elements.