LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamically naming clusters for JSON

Solved!
Go to solution

I am trying to create a JSON formatted output that dynamically changes the name of the JSON object based on the loop iteration.Dynamic JSON.png

Right now my output formatting is like this:

{
    "Variant":{
        "Letter":"VIL",
        "Number":9
    }
}{
    "Variant":{
        "Letter":"RVK",
        "Number":8
    }
}
...

 But I want it to appear as this:

{
    "Loop Number 1":{
        "Letter":"VIL",
        "Number":1
    "Loop Number 2":{
        "Letter":"RVK",
        "Number":2
    }
    ....
}

What am I doing wrong, and what do I need to do to make it right?

0 Kudos
Message 1 of 3
(2,306 Views)

Hi smurfinturf,

I doubt you really want to use variants and flatten to string.

Here's how I'd build that formatted string:

 

Hope it helps!

0 Kudos
Message 2 of 3
(2,272 Views)
Solution
Accepted by topic author smurfinturf

@550nm wrote:

 

Here's how I'd build that formatted string:

 


Don't do that.  Use a JSON library; that way you will not get bugs due to edge-cases that you miss when using standard string formating instead of a library that follows the full JSON standard.

 

Here's an example using JSONtext:

 

0 Kudos
Message 3 of 3
(2,259 Views)