Jump to content

Unflatten from JSON and variant to data


Recommended Posts

Hi,

I'm receiving a JSON string from a web API, which I'm trying to convert into a cluster (of clusters) but I've run into some problems:

1) Sometimes the order of the elements in the JSON string changes, which causes my conversion to fail.

2) Sometimes the "object" returned via JSON is null, which causes my conversion to fail if I use clusters within clusters. It works with variants in clusters but then I need to convert the all the variants manually

Is there any way to improve my code to fix those problems? The attached snippet is a simplified version. In my project, the first JSON string to data is done in a library. The second conversion from "result" variant to data is done in my application. This makes a direct conversion from JSON string more difficult.

snip2.png

Link to comment
35 minutes ago, ThomasGutzler said:

1) Sometimes the order of the elements in the JSON string changes, which causes my conversion to fail.

2) Sometimes the "object" returned via JSON is null, which causes my conversion to fail if I use clusters within clusters. It works with variants in clusters but then I need to convert the all the variants manually

To solve both issues, insert "Adapt to Type.vi" before "Variant to Data". However, your cluster element names are now case-sensitive. "TimeStamp" will not match "timeStamp" in the JSON string.

  • Like 1
Link to comment
1 hour ago, smithd said:

Drjdpowell's json library has functionality for breaking subclusters apart and all sorts of other useful ways of manipulating the json strings directly. If you can use 2017 its worth a look.

Unfortunately, I'm still stuck in 2016 land.

But JKSH's suggestion got me going. Thanks

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.