Leandro Feder Posted December 18, 2024 Report Posted December 18, 2024 (edited) Hello I need to create a json in the following structure: { "Value1": { "Build": { "1": { "t_inst": { "Type": "Gold", "Key": "15", "size": "big" }, "1_avg": { "Type": "Green", "Key": "11", "size": "big" }, "2_avg": { "Type": "Blue", "Key": "21", "size": "big" } }, "2": { "t_inst": { "Type": "Gold", "Key": "15", "size": "big" }, "1_avg": { "Type": "Green", "Key": "11", "size": "big" }, "2_avg": { "Type": "Blue", "Key": "21", "size": "big" } } } }, "Value2": { "Build": { "1": { "t_inst": { "Type": "Grey", "Key": "22", "size": "small" }, "1_avg": { "Type": "Yellow", "Key": "8", "size": "big" }, "2_avg": { "Type": "Blue", "Key": "21", "size": "big" } } } } } I've searched several forums, but none I've seen have as many layers as I need. Could someone help me? Edited December 18, 2024 by Leandro Feder Quote
Phillip Brooks Posted December 19, 2024 Report Posted December 19, 2024 Your JSON has patterns in it that infer lists/arrays of data that could be of variable length. This would be difficult to create with the native JSON functions in LabVIEW. I would suggest using the JSONText Toolkit - https://www.vipm.io/package/jdp_science_jsontext/?utm_source=vipm_desktop Quote
Leandro Feder Posted December 19, 2024 Author Report Posted December 19, 2024 (edited) I create a VI to do that, but i'm not getting success My actual structure is on this formact: {"EQ1": { "TCP": { "1": {}, {"EQ1": { "TCP": { "2": {}, {"EQ1": { "TCP": { "3"{} } }, "EQ2": { "TCP": { "1":{}, "EQ2": { "TCP": { "2":{}, "EQ2": { "TCP": { "3":{} } } I'm trying to do the folowing thing (the correct structure for json): {"EQ1": { "TCP": { "1": {}, "2": {}, "3"{} } }, "EQ2": { "TCP": { "1":{}, "2":{}, "3":{} } } Could you help me assemble my json into this structure? BuildJSONtoForum.viFetching info... Edited December 19, 2024 by Leandro Feder Quote
Popular Post LogMAN Posted December 29, 2024 Popular Post Report Posted December 29, 2024 The examples you provide are invalid JSON, which makes it difficult to understand what you are actually trying to do. In your VI, the input data is a 2D array of string but the JSON output is completely different. Your first step should be to define the types you need to produce the expected JSON output. Afterwards you can map your input data to the output data and simply convert it to JSON. The structure of the inner-most object in your JSON appears to be the following: { "Type":"ABC", "IP":"192.168.0.0", "Port":111, "Still":1, "Register":"Register", "Address":12345, "SizeLength":1, "FET":2, "Size":"big", "Conversion":"small" } In LabVIEW, this can be represented by a cluster: When you convert this cluster to JSON, you'll get the output above. Now, the next level of your structure is a bit strange but can be solved in a similar manner. I assume that "1", "2", and "3" are instances of the object above: { "1": {}, "2": {}, "3": {} } So essentially, this is a cluster containing clusters: The approach for the next level is practically the same: { "TCP": {} } And finally, there can be multiple instances of that, which, again, works the same: { "EQ1": {}, "EQ2": {} } This is the final form as far as I can tell. Now you can use either JSONtext or LabVIEW's built-in Flatten To JSON function to convert it to JSON {"EQ1":{"TCP":{"1":{"Type":"ABC","IP":"192.168.0.0","Port":111,"Still":1,"Register":"Register","Address":12345,"SizeLength":1,"FET":2,"Size":"big","Conversion":"small"},"2":{"Type":"ABC","IP":"192.168.0.0","Port":111,"Still":1,"Register":"Register","Address":12345,"SizeLength":1,"FET":2,"Size":"big","Conversion":"small"},"3":{"Type":"ABC","IP":"192.168.0.0","Port":111,"Still":1,"Register":"Register","Address":12345,"SizeLength":1,"FET":2,"Size":"big","Conversion":"small"}}},"EQ2":{"TCP":{"1":{"Type":"ABC","IP":"192.168.0.0","Port":111,"Still":1,"Register":"Register","Address":12345,"SizeLength":1,"FET":2,"Size":"big","Conversion":"small"},"2":{"Type":"ABC","IP":"192.168.0.0","Port":111,"Still":1,"Register":"Register","Address":12345,"SizeLength":1,"FET":2,"Size":"big","Conversion":"small"},"3":{"Type":"ABC","IP":"192.168.0.0","Port":111,"Still":1,"Register":"Register","Address":12345,"SizeLength":1,"FET":2,"Size":"big","Conversion":"small"}}}} The mapping of your input data should be straight forward. 3 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.