4

I have to retrieve data from some site that sends back responses with edn bodies. I am trying to convert the sent back Edn to Json so I can parse it with Jsoup.

I found a website that was able to do the conversion, but how do I implement something like this in java?

I tried something like this, but it didn't a full job:

public static String edmToJson(String edm) {
    String json = edm;
    json = json.replaceFirst("(\\(\\{).*?(}\\))", "1").replace("(", "").replace("})", "").replace("} {", "},{");
    return json;
}

Is there a way to do it without using closure?

Rafat Mahmoud
  • 130
  • 3
  • 16
  • Does this answer your question? [How to print EDN output in JSON format using Cheshire custom encoder](https://stackoverflow.com/questions/60331109/how-to-print-edn-output-in-json-format-using-cheshire-custom-encoder) – JoSSte Jun 06 '20 at 10:28
  • @JoSSte I was hoping for a purely java code approach. I don't know anything about closure. – Rafat Mahmoud Jun 06 '20 at 10:30
  • something like https://github.com/mikera/edn-pojos ? – JoSSte Jun 06 '20 at 14:51

1 Answers1

1

You can parse EDN data in java by using a library like edn-java.

Sample usage:

@Test
public void simpleUsageExample() throws IOException {
    Parseable pbr = Parsers.newParseable("{:x 1, :y 2}");
    Parser p = Parsers.newParser(defaultConfiguration());
    Map<?, ?> m = (Map<?, ?>) p.nextValue(pbr);
    assertEquals(m.get(newKeyword("x")), 1L);
    assertEquals(m.get(newKeyword("y")), 2L);
    assertEquals(Parser.END_OF_INPUT, p.nextValue(pbr));
}

Complete docs available at edn-java

Smile
  • 3,832
  • 3
  • 25
  • 39