-1
{
  "description": "Something",
  "id": "abc.def.xyzjson#",
  "type": "object",
  "properties": {
    "triggerTime": {
      "description": "Something",
      "$ref": "abc.def.xyz.1.json#"
      "required": true
    },
    "customerId": {
      "type": "string",
      "description": "Something",
      "$ref": "abc.def.xyz.1.json#"
    },

..... many more keys........ I need to go into the $ref file location and lode that json into a map Please help me out how to read. Already I am able to read the main file like

File jsonInputFile = new File("location");
System.out.println("Keys : " + entry2.getKey());
Vishnu T S
  • 3,476
  • 2
  • 23
  • 39

1 Answers1

0

You can try below code for getting the $ref value

import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
public class Test{

    public static void main(String[] args) {
        JSONParser parser = new JSONParser();

        try {

            Object obj = parser.parse(new FileReader(
                    "File location"));
            JSONObject jsonObject = (JSONObject) obj;
            JSONObject properties = (JSONObject) jsonObject.get("properties");
            JSONObject triggerTime = (JSONObject) properties.get("triggerTime");
            String ref = (String) triggerTime.get("$ref");//You can load this file to a map if required.
            System.out.println(ref);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

output is

abc.def.xyz.1.json#

Vishnu T S
  • 3,476
  • 2
  • 23
  • 39