简体   繁体   中英

Merging JSON files using text pad

I am looking to merge two json messages. What I found is that it is a lot more difficult than I thought.. it needs to be parsed and serialized. The new JSON looks nothing like either input JSON file...

Why can't just cut and paste to generate a new JSON file? Do I have to do it programmatically?

You could try using jQuery's extend feature for merging two (or however many json messages). The syntax for merging your two messages and saving the result to a new object would be:

var both = jQuery.extend({},json_object_one,json_object_two);

both will now store the merged json message. This is far simpler than merging the file by hand in a text editor. For more on this method: http://api.jquery.com/jQuery.extend/

EDIT:
Actually you're going to want to do var both = jQuery.extend(true,{},obj_one,obj_two); . The true flag turns on deep copy, which will recursively merge any inner objects in the JSON object.

您可以手动执行此操作,因为json仅是普通的javascript,如果您有大量的程序来处理它会有所帮助。

Example messages would be helpful. If both represent the same data set then cut and paste should be fine.

You can format the JSON at JSON Format and that may make your job easier.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM