code: public static void writeJsonValueMap(JsonWriter writer, StringFilter filter,
                                           ValueMap values, MappingRules mapping)
              throws RepositoryException, IOException {
          if (values != null) {
              TreeMap<String, Object> sortedProperties = new TreeMap<>();
              Iterator<Map.Entry<String, Object>> iterator = values.entrySet().iterator();
              while (iterator.hasNext()) {
                  Map.Entry<String, Object> entry = iterator.next();
                  String key = entry.getKey();
                  if (filter.accept(key)) {
                      sortedProperties.put(key, entry.getValue());
                  }
              }
              if (mapping.propertyFormat.scope == MappingRules.PropertyFormat.Scope.value) {
                  writer.beginObject();
              } else {
                  writer.beginArray();
              }
              for (Map.Entry<String, Object> entry : sortedProperties.entrySet()) {
                  writeJsonProperty(writer, entry.getKey(), entry.getValue(), mapping);
              }
              if (mapping.propertyFormat.scope == MappingRules.PropertyFormat.Scope.value) {
                  writer.endObject();
              } else {
                  writer.endArray();
              }
          }
      }
docs: Write all properties of an node accepted by the filter into an JSON array.
  
  @param writer the JSON writer object (with the JSON state)
  @param filter the property name filter
  @param values the Sling ValueMap to write
  @throws javax.jcr.RepositoryException error on accessing JCR
  @throws java.io.IOException           error on write JSON