Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does such a JSON string builder exist?

Tags:

java

json

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"}}
like image 767
digiarnie Avatar asked Jun 21 '10 01:06

digiarnie


People also ask

What is a String builder?

StringBuilder in Java is a class used to create a mutable, or in other words, a modifiable succession of characters. Like StringBuffer, the StringBuilder class is an alternative to the Java Strings Class, as the Strings class provides an immutable succession of characters.

How do I convert a String to a String builder?

Converting a String to StringBuilder The append() method of the StringBuilder class accepts a String value and adds it to the current object. To convert a String value to StringBuilder object just append it using the append() method.

Can you compare String to StringBuilder?

We can use the equals() method for comparing two strings in Java since the String class overrides the equals() method of the Object class, while StringBuilder doesn't override the equals() method of the Object class and hence equals() method cannot be used to compare two StringBuilder objects.


1 Answers

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

like image 108
Behrang Avatar answered Sep 23 '22 07:09

Behrang