tags:

views:

227

answers:

3

I'm looking to do something like the following in Java and was wondering whether such a JSON library/helper already existed out there somewhere?

SomeJsonBuilder builder = new SomeJsonBuilder();
builder.add("one", "oneValue");
builder.add("two.three", "threeValue");
String output = builder.toString();

Such that the output string above would be something like:

{"one":"oneValue", "two":{"three":"threeValue"}}
A: 

Not straightforward, but I'd combine JAXB, Jackson and BeanUtils.

Here's one part http://ondra.zizka.cz/stranky/programovani/java/jaxb-json-jackson-howto.texy

Here's the other... http://commons.apache.org/beanutils/api/org/apache/commons/beanutils/expression/DefaultResolver.html

Ondra Žižka
A: 

Is this what you're looking for? http://www.json.org/java/

Ben J
I've had a look at the classes there but I don't think I see a class that accepts the kind of notation I'm after. They all seem to want to build up objects before toString'ing. Ideally I'd like a utility that takes in the notation I mentioned in my post (I've already this utility but of course it'd be nice if there was one that was well tested and used already)
digiarnie
+1  A: 

Have you checked JSONLib? It doesn't do exactly what you're looking for though. But it is close.

Bytecode Ninja
The map function is probably the closest. Thanks ninja!
digiarnie