This repository was archived by the owner on Nov 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Deep Searcher
MatthewTGM edited this page Jun 30, 2021
·
1 revision
import xyz.matthewtgm.json.entities.JsonObject;
import xyz.matthewtgm.json.entities.JsonPrimitive;
import xyz.matthewtgm.json.util.JsonHelper;
import java.util.Random;
public class DeepSearcherExampleApplication {
public static DeepSearcherExampleApplication instance = new DeepSearcherExampleApplication();
public void start() {
JsonObject object = new JsonObject();
object.add("random", new Random().nextInt());
object.add("nested", new JsonObject()
.add("data", new JsonObject()
.add("title", "MVP")));
System.out.println(JsonHelper.deepSearchKey("title", object)); /* Returns true, only checks keys */
System.out.println(JsonHelper.deepSearchValue(new JsonPrimitive("MVP"), object)); /* Returns true, only checks values. */
System.out.println(JsonHelper.deepSearch("title", object)); /* Returns true, checks both keys and values. */
}
public static void main(String[] args) {
DeepSearcherExampleApplication.instance.start();
}
}The deep searcher iterates over all nested objects and arrays to look for a key or value. This is especially helpful when you're unsure what object or array contains what you're looking for.