JSON/XElement merge


#1

Hello!
Let’s assume there is a settings.json with the basic settings as objects inside, I’m loading it into vvvv with xelement. I’m trying to “overwrite” the objects inside in an automated manner. The new objects are send into vvvv in realtime. If there is a new object-value, color,… then the new data should be displayed. if not, the settings should be used. I managed to prune every possible objectname and overwrite with a simple switch(string), but i need to set a prune for every objectname i’m using. I’d like to merge these automated since objects may be nested or arrays. Maybe someone has a hint. :)


#2

that sounds like a job for vl, that allows you to deal with this on an “object” level rather than a string level. can you share the settings file so we can make this into a little demo?


#3

Hello Joreg,

Yes, VL might be useful here. I uploaded a sample JSON without real content and a small patch. Let’s say the Live Input will be stored in a S+H and can then be applied on the settings.
JSON merge.zip (2.5 KB)

Best, Andreas


#4

ouright, even easier than i thought, since Json.NET comes with readytouse json.Merge() functionality that seems to do exactly what you’re looking for.

so all i had to do was reference Newtonsoft.Json as a dependency to the document:

and then follow the c# demo code for the json.Merge():

vl’a!
mergejson.zip (13.2 KB)

edit: forgot to mention, this works only with latest alphas!


#5

Thank you Joreg, that’s exactly what I need! There are only two small things: when the JSON is not 100% correct, e.g. a comma is missing, a errormessage pops up. not very handy sometimes and the fact that it’s in the alpha release. Are there plans for the 36 release?
Thanks!


#6

start vvvv with /showexceptions false parameter.
see https://vvvv.org/documentation/commandline-parameters


#7

this will of course work with upcoming b36.

regarding the invalid json…as @tgd pointed out the error popup is alpha only and you can disable it which would simply give you a red node then. apart from that what else would you expect it should do with such an invalid json?