The KJSON format


JSON Format:

{
  "songURL": "D:\\Laym\\Music\\Dance Wiv Me (feat. Calvin Harris & Chrome).mp3",
  "songAlbumCoverURL": "",
  "songTitle": "Dance Wiv Me",
  "songArtist": "Dizzee Rascal",
  "lyrics": [ ... ],
  "startTimes": [ ... ],
  "durations": [ ... ]
}

Format Explanation

songURL

Song URL is a STRING type variable that stores the path to the audio file on the system and is used later on by a few different scripts in the backend.

songAlbumCoverURL

songAlbumCoverURL is a STRING type variable that stores the path to the album cover art on the system. In the case of the example above, no Album Cover URL was parsed, this variable is optional.

- Song Title and Artist self-explanitory-

lyrics

The Lyrics variable is a JSON array that stores all words of the song.


Attached to this devlog post is an example of a typical KJSON file with data.

How to parse it:

public class SongDataParser : MonoBehaviour
{
    [Serializable]
    public class SongData
    {
        public string songURL;
        public string songAlbumCoverURL;
        public string songTitle;
        public string songArtist;
        public List<string> lyrics;
        public List<float> startTimes;
        public List<float> durations;
    }
    public static SongData LoadSongData(string jsonFilePath)
    {
        if (!File.Exists(jsonFilePath))
        {
            Debug.LogError($"File not found at {jsonFilePath}");
            return null;
        }
        try
        {
            string jsonContent = File.ReadAllText(jsonFilePath);
            SongData songData = JsonUtility.FromJson<SongData>(jsonContent);
            Debug.Log($"Successfully parsed song data: {songData.songTitle} by {songData.songArtist}");
            return songData;
        }
        catch (Exception e)
        {
            Debug.LogError($"Failed to parse JSON: {e.Message}");
            return null;
        }
    }
    private void Start()
    {
        string filePath = Path.Combine(Application.dataPath, "songData.json");
        SongData songData = LoadSongData(filePath);
        if (songData != null)
        {
            Debug.Log($"Song Title: {songData.songTitle}");
            Debug.Log($"Lyrics Count: {songData.lyrics.Count}");
            for (int i = 0; i < songData.lyrics.Count; i++)
            {
                Debug.Log($"[{songData.startTimes[i]}s]: {songData.lyrics[i]} (Duration: {songData.durations[i]}s)");
            }
        }
    }
}

Files

Karaoke Editor 45 MB
Dec 09, 2024
Example KJSON 4 kB
2 hours ago

Get Karaoke Editor

Leave a comment

Log in with itch.io to leave a comment.