cancel
Showing results for 
Search instead for 
Did you mean: 

Downloading a JSON file after hitting soap UI https request

ZDGN
Contributor

Re: Downloading a JSON file after hitting soap UI https request

Hi @sparrowenclave,

 

Here is a sample script to browse a directory containing json files and open each to find a specific node.

 

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import static java.util.stream.Collectors.toList;

File newFile;
String FolderPath = "<insert your path here>";
File selectedDirectory = new File(FolderPath);
List<Path> paths = new ArrayList<>();

try {
  paths = Files.walk(Paths.get(new File(selectedDirectory.getPath())
              .getAbsolutePath()))
              .filter(p -> p.toFile().isFile())
              .collect(toList());
} catch (IOException e) {
  e.printStackTrace();
}

for (Path path : paths) {
  newFile = new File(path.toString());
  ObjectMapper mapperFileSource = new ObjectMapper();
  JsonNode rootNode = null;
  try {
      rootNode = mapperFileSource.readTree(newFile);
  } catch (IOException e) {
      e.printStackTrace();
  }
  JsonNode searchNode = rootNode.findValue("<insert a node name here>");
  if (searchNode != null) {
      log.info(searchNode.textValue());
      // You can add assertions here
  }
}

 

It is just an example of what can be done.

Keep in min you'll need jackson's library.
Hope this will help.

 

David.

richie
Community Hero

Re: Downloading a JSON file after hitting soap UI https request

@ZDGN,

This is great...people ask for this every so often and now there's a definite way of doing it. I'll be saving this for when this pops up in my work, so nice one!

Rich
if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
New Here?
Join us and watch the welcome video:
Top Kudoed Authors