I have a project that's making heavy use of JKI JSON in conjunction with OpenG Variant toolkit. For a bit of context, I'm communicating with an instrument server via JSON-RPC over websocket.
I can access properties of the server by sending a "Query" command, with an empty JSON object corresponding to the desired property in the "params" field. In Labview, it looks something like this:
which ends up sending a JSON-RPC message like this to the server:
{
"jsonrpc":"2.0",
"method":"Query",
"params":{
"filter":{
"SomeNumericValue":{
}
}
},
"id":"bar"
}
From time to time, I need to query data that's returned in the form of a dictionary. For example, the server maintains a database of user-defined instrument settings, with each settings object labeled by a guid string. I can retrieve all dictionary elements in one go with an empty object labeled "{}". Then I can restructure them into a more LV-amenable array using OpenG Variant tricks. So far so good. The Labview looks like this:
Just for total clarity, the JSON-RPC message sent from my client looks like this:
{
"jsonrpc":"2.0",
"method":"Query",
"params":{
"filter":{
"SomeDictionary":{
"{}":{
}
}
}
},
"id":"bar"
}
Unfortunately, the full database can be really big and unwieldy. Each item in the dictionary is itself a pretty bulky object. (Side note: I sadly think I've discovered that it can break the JKI JSON parser. I'm not sure how this happens - maybe a memory issue when recursion gets really, really deep. Don't shoot me if I'm wrong about that. JKI JSON is saving my life right now, so I don't want to speak ill of it!) I would really like to query just one dictionary element at a time. In terms of how my code currently works, that would require changing the wildcard "{}" label within the filter object structure to the actual name of of the item I want to grab. (Knowing the item names is no problem. I can retrieve a list of names from a separate query.)
So far I haven't figured out how to do this. Maybe it's not even possible. (Just wiring a variant to Set Data Name.vi and then using Bundle's to build up a cluster doesn't work. The element in the cluster will be named "Renamed Data" - i.e., the output name of Set Data Name.vi.)
For the record, no, I do not like the fact that the server spits out dictionaries, as these naturally map onto a cluster of clusters (object of other named objects), and Labview desperately wants all objects to already be named at runtime. But this is just how the device works, and I can't change it.