Comments (20)
Original comment by [email protected]
on 14 Jul 2010 at 1:16
- Changed state: Accepted
- Added labels: Type-Enhancement
- Removed labels: Type-Defect
from json-simple.
Having pretty print would be a great feature for the library.
Original comment by [email protected]
on 17 Sep 2010 at 12:46
from json-simple.
It would indeed be useful. Will this be integrated ?
Original comment by [email protected]
on 6 Oct 2010 at 7:24
from json-simple.
I do not have the bandwidth to shepherd this patch. For anyone interested in
using it, I've attached my source code. You can use it by replacing the source
in an existing project.
Original comment by [email protected]
on 6 Oct 2010 at 7:55
Attachments:
from json-simple.
Your patch has some strange differences with the trunk in SVN, a couple of
methods are removed... are you sure you used the trunk to make your changes ?
Original comment by [email protected]
on 6 Oct 2010 at 10:51
from json-simple.
The strange differences are entirely possible, once I gave up on the idea of
submitting a patch, I might have gotten creative. I did use the trunk as it was
about 6 months ago.
Original comment by [email protected]
on 6 Oct 2010 at 11:12
from json-simple.
Pretty printing is a nice feature for this lib, but I argue that this should be
implemented as a stand alone component using the lexer to read JSON and then
write the output according to some configuration. It should not be that hard to
implement nor would it have to be expensive for the VM.
The only change to the core that makes sense to me is to replace #toJSONString
to use a PrintWriter rather than a StringBuffer (why isn't this a
StringBuilder?) in order to make it a true streaming API.
Original comment by [email protected]
on 7 Oct 2010 at 11:02
from json-simple.
Well I ended up needing a JSON library and I liked this one but I needed it
pretty-printed good thing the source was here so I could customize it...
Im posting the code here hope u guys find it useful =)
Changes I made:
Added a class named:
---> JSONPrettyPrint.java
Added 2 methods at JSONValue.java named:
---> writePrettyJSONString
---> toPrettyJSONString
Added 2 methods at JSONArray.java named:
---> writePrettyJSONString
---> toPrettyJSONString
the output should be something like this:
{
"k3":["lv1","lv2"],
"k1":"v1",
"k2":
{
"mk1":"mv1",
"mk2":["lv1","lv2"]
}
}
or even like this:
{
"k3":["lv1","lv2"],
"k1":"v1",
"k2":
{
"mk1":"mv1",
"mk2":["lv1","lv2"]
}
"k3":[
{
"zk1":"zv1",
"zk2":"zv2"
}]
}
another change I made is that '/' is not considered an escape character in
Java, so I commented the code that turns it into '\/' because it was messing
all my stuff here
Original comment by [email protected]
on 25 Nov 2010 at 5:58
Attachments:
- [json simple modified to pretty print.zip](https://storage.googleapis.com/google-code-attachments/json-simple/issue-22/comment-8/json simple modified to pretty print.zip)
from json-simple.
I also need the pretty printing for json string.
So not to change/extend the json-simple classes, I created a new type of
java.io.Writer that adds indentation.
Attaching the source here.
To use it:
Writer writer = new JSonWriter(); // this is the new writter that adds
indentation.
jsonObject.writeJSONString(writer);
Original comment by [email protected]
on 28 Nov 2011 at 4:44
Attachments:
from json-simple.
I think the writer approach is great. Good work. I hope pretty printing becomes
a standard in JSON Simple. I have reviewed many JSON libraries and this is the
best for it's flexibility and easy of use. Pretty printing was my only gripe.
Original comment by [email protected]
on 29 Nov 2011 at 1:36
from json-simple.
Thank you all for the help. May consider it in future release.
Original comment by [email protected]
on 29 Nov 2011 at 3:31
from json-simple.
JSonWriter is a cool solution! This is all what I want to have. Thank you very
much for the work.
Original comment by [email protected]
on 22 Aug 2012 at 7:44
from json-simple.
I guess if after three years no one has added a few newlines and an indent
counter, it's not going to happen... Too bad---it looked like a nice little
library.
Original comment by [email protected]
on 28 Jan 2013 at 9:04
from json-simple.
+1 for the JSONWriter, it should be added to the project
Original comment by [email protected]
on 3 Sep 2013 at 4:09
from json-simple.
In one line:
String niceFormattedJson = JsonWriter.formatJson(jsonString)
The json-io libray (https://github.com/jdereg/json-io) is a small (75K) library
with no other dependencies than the JDK.
In addition to pretty-printing JSON, you can serialize Java objects (entire
Java object graphs with cycles) to JSON, as well as read them in.
Original comment by [email protected]
on 24 Feb 2014 at 6:18
from json-simple.
Thank you thanks a lot
Original comment by [email protected]
on 4 Mar 2014 at 6:38
from json-simple.
Thank you for your solution, Elad. Unfortunately, it's not aware of special
characters which are part of strings, but it's still helpful.
jdereg, ironically, the json-io library depends on gson, which is the 200K
library I was using before I tried to switch to json-simple.
Original comment by [email protected]
on 3 Sep 2014 at 5:14
from json-simple.
Minor improvements for the great Elad's contribution: configurable space after
colon, more readable code.
Original comment by [email protected]
on 2 Apr 2015 at 10:21
Attachments:
from json-simple.
I just want to note that this issue has been addressed in my fork (which is fully compatible with this library if you're using java 7+). You can find more details about it here: https://cliftonlabs.github.io/json-simple/
from json-simple.
Minor improvements for the great Elad's contribution: configurable space after colon, more readable code.
Original comment by
[email protected]
on 2 Apr 2015 at 10:21Attachments:
The specified bucket doesn't exist. Can you please update attachment?
from json-simple.
Related Issues (20)
- .Net Implementation
- nullpointer when parsing JSON that starts with Array HOT 1
- Request: New Maven release for Junit dependency scope change HOT 3
- Task :test FAILED org.json.simple.Test > testDecode HOT 1
- No Pretty String output option HOT 2
- Is this dependency was include on the default project that generate from Android Studio?
- getPosition() result from ParseException its diferent that the real character position
- Having error 'cannot be cast to class'.
- Unexpected character () at position 0 HOT 1
- Make new release to address CVE-2020-15250 HOT 8
- Bug: StackOverflow in toString() (infinite recursion)
- When will be next release?
- Integrating json-simple into OSS-Fuzz
- defaulting keys to String and using an efficient HashMap for small data could increase the performance. HOT 2
- Stack overflow error caused by json-simple serialization Map
- Stack overflow error caused by json-simple serialization List
- Nested get
- Include Code coverage to JSON Simple
- Activate github actions for pull requests
- ItemList is vulnerable to out of denial of service (DoS) attack
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from json-simple.