void JsonTestApp::mouseDown( MouseEvent event ) { JsonTree doc; JsonTree library = JsonTree::makeObject( "library" ); JsonTree album = JsonTree::makeArray( "album" ); album.pushBack( JsonTree( "musician", string( "Sufjan Stevens" ) ) ); album.pushBack( JsonTree( "year", string( "2004" ) ) ); album.pushBack( JsonTree( "title", string( "Seven Swans" ) ) ); JsonTree tracks = JsonTree::makeArray( "tracks" ); for ( int32_t i = 0; i < 6; i ++ ) { JsonTree track; track.pushBack( JsonTree( "id", i + 1 ) ); JsonTree title; switch ( i ) { case 0: title = JsonTree( "title", "All the Trees of the Field Will Clap Their Hands" ); break; case 1: title = JsonTree( "title", "The Dress Looks Nice on You" ); break; case 2: title = JsonTree( "title", "In the Dev Hole's Territory" ); break; case 3: title = JsonTree( "title", "To Be a Clone With You" ); break; case 4: title = JsonTree( "title", "To Be Removed" ); break; case 5: title = JsonTree( "title", "To Be Removed" ); break; } track.pushBack( title ); tracks.pushBack( track ); } for ( JsonTree::Iter trackIt = tracks.begin(); trackIt != tracks.end(); ++trackIt ) { if ( trackIt->getChild( "id" ).getValue<int>() == 3 ) { JsonTree track; track.pushBack( JsonTree( "id", 3 ) ); track.pushBack( JsonTree( "title", "In the Devil's Territory" ) ); tracks.replaceChild( trackIt, track ); } } JsonTree track; track.pushBack( JsonTree( "id", 4 ) ); track.pushBack( JsonTree( "title", "To Be Alone With You" ) ); tracks.replaceChild( 3, track ); tracks.removeChild( 4 ); for ( JsonTree::Iter trackIt = tracks.begin(); trackIt != tracks.end(); ) { if ( trackIt->getChild( "id" ).getValue<int>() == 6 ) { trackIt = tracks.removeChild( trackIt ); } else { ++trackIt; } } album.pushBack( tracks ); library.pushBack( album ); doc.pushBack( library ); console() << doc; doc.write( writeFile( getDocumentsDirectory() + "testoutput.json" ), false ); }