private static void buildSessionDataFile(@NotNull Project project,
                                           @NotNull List<? extends UsageCluster> clusters,
                                           @NotNull ProgressIndicator indicator,
                                           @NotNull String fileName) throws IOException {
    int counter = 0;
    StringWriter stringWriter = new StringWriter();
    JsonGenerator generator = new JsonFactory().createGenerator(stringWriter);
    generator.writeStartArray();
    for (UsageCluster cluster : clusters) {
      indicator.setFraction(counter++ / (double)clusters.size());
      Set<SimilarUsage> usages = cluster.getUsages();
      for (SimilarUsage usage : usages) {
        if (usage instanceof UsageInfo2UsageAdapter) {
          indicator.checkCanceled();
          PsiElement element = getElement((UsageInfo2UsageAdapter)usage);
          generator.writeStartObject();
          generator.writeStringField(FILENAME, getUsageId(element));
          generator.writeStringField(SNIPPET, getUsageLineSnippet(project, element));
          generator.writeNumberField(CLUSTER_NUMBER, counter);
          generator.writeObjectFieldStart(FEATURES);
          List<Object2IntMap.Entry<String>> sortedEntries = Stream.concat(getPrimaryFeatures(usage.getFeatures()), getStructuralFeatures(usage.getFeatures())).toList();
          for (Object2IntMap.Entry<String> entry : sortedEntries) {
            generator.writeNumberField(entry.getKey(), entry.getIntValue());
          }
          generator.writeEndObject();
          generator.writeEndObject();
        }
      }
    }
    generator.writeEndArray();
    generator.close();

    writeCommandAction(project).run(() -> {
      createScratchFile(stringWriter.toString(), fileName);
    });
  }
private static void buildSessionDataFile(@NotNull Project project,
                                           @NotNull List<? extends UsageCluster> clusters,
                                           @NotNull ProgressIndicator indicator,
                                           @NotNull String fileName)