Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
103 views
in Technique[技术] by (71.8m points)

java - Best way to add a property to JSON without reading in memory

I have a large JSON and complex file (~100MB). I need to add a property to it without reading in memory. I am unable to find an option to append to JSON without reading the entire content in memory.

I couldn't find any suitable example.

The best I could think of is to replace the last } with "key":"value"} using StreamReader(s) and StreamReader(s)

The JSON is read through a legacy application and we are integrating it to a web application and hence this is becoming a bottleneck.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you are unwilling to parse data, I think you should use Java.io.RandomAccessFile. The package will allow you to seek to the end of the file, (or 1 before the end), and write your new data. Keep in mind, the writer overrwrites strings, it does not insert them, so assuming you want to add "key": property,, you'll need to remember to insert ,"key": property}


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...