adding json code (has memory leak)