conditional probability table to Json

I am looking for an elegant way to turn conditional probability tables (cpt) into Json Format.

e.g. turn

X|Y| z | -z |
1|1| 0.4 | 0.6 |
1|0| 0.7 | 0.3 |
0|1| 0.1 | 0.9 |
0|0| 1.0 | 0.0 |

into

        [
            [              
                [          
                    0.4,   //P(z|x,y)
                    0.6    //P(-z|x,y)
                ],
                [
                    0.7,   //P(z|x,-y)
                    0.3    //P(-z|x,-y)
                ]
            ],
            [
                [
                    0.1,   //P(z|-x,y)
                    0.9    //P(-z|-x,y)
                ],
                [
                    1,     //P(z|-x,-y)
                    0      //P(-z|-x,-y)
                ]
            ]
        ]

As this looks like a common problem to me, I am hoping anyone can set me up with some example code