web/play-java-forms/src/main/java/play/data/Form.java
public JsonNode errorsAsJson(Lang lang) {
    Map<String, List<String>> allMessages = new HashMap<>();
    errors.forEach(
        error -> {
          if (error != null) {
            final List<String> messages = new ArrayList<>();
            if (messagesApi != null && lang != null) {
              final List<String> reversedMessages = new ArrayList<>(error.messages());
              Collections.reverse(reversedMessages);
              messages.add(
                  messagesApi.get(
                      lang,
                      reversedMessages,
                      translateMsgArg(error.arguments(), messagesApi, lang)));
            } else {
              messages.add(error.message());
            }
            allMessages.put(error.key(), messages);
          }
        });
    return play.libs.Json.toJson(allMessages);
  }
public JsonNode errorsAsJson(Lang lang) {
    Map<String, List<String>> allMessages = new HashMap<>();
    errors.forEach(
        error -> {
          if (error != null) {
            final List<String> messages = new ArrayList<>();
            if (messagesApi != null && lang != null) {
              final List<String> reversedMessages = new ArrayList<>(error.messages());
              Collections.reverse(reversedMessages);
              messages.add(
                  messagesApi.get(
                      lang,
                      reversedMessages,
                      translateMsgArg(error.arguments(), messagesApi, lang)));
            } else {
              messages.add(error.message());
            }
            allMessages.put(error.key(), messages);
          }
        });
    return play.libs.Json.toJson(allMessages);
  }
Returns the form errors serialized as Json using the given Lang.

@param lang the language to use.
@return the JSON node containing the errors.