• Editor
  • Converting JSON files from 3.6 to 3.8

I upgraded unity-spine to 3.8, my existing Spine .JSON files (3.6) were not loading anymore inside Unity and the artist who made them was not available to re-export them (20-30 files).

To fix that, I made a small CLI PHP script that work good enough for me, It's a quick 30 minutes hack but It could work for you too, here is the code, for me it was a huge time saver:

<?php

set_time_limit(0);

function convert_file($file_input) {
   
if (!file_exists("input/".$file_input)) { die("File not found!\r\n"); } $data = json_decode(file_get_contents("input/".$file_input)); $data->skeleton->spine = "3.8.91"; $skins = $data->skins; $new_skins = []; // Fix to skins foreach($skins as $key => $value) {
$item = []; $item["name"] = $key; $item["attachments"] = []; foreach($value as $k => $v) { $item["attachments"][$k] = $v; } $new_skins[] = $item; } $data->skins = $new_skins; $animations = $data->animations; foreach($animations as $key => &$value) { foreach($value as $k => &$v) { foreach($v as $k2 => &$v2) { foreach($v2 as $k3 => &$v3) { if (!is_array($v3)) continue; for($i=0;$i<count($v3);$i++) { if (is_array($v3[$i])) continue; if (isset($v3[$i]->curve)) { $c = $v3[$i]->curve; $v3[$i]->curve = $c[0]; $v3[$i]->c2 = $c[1]; $v3[$i]->c3 = $c[2]; $v3[$i]->c4 = $c[3]; } } } } } } $data->animations = $animations; $fd = fopen("output/".$file_input, "w"); fwrite($fd, json_encode($data, JSON_PRETTY_PRINT)); fclose($fd); } $dir = opendir("input"); while($file = readdir($dir)) { if ($file[0] == ".") continue; if (!is_file("input/".$file)) continue; if (strpos($file,".json") === false) continue;
print "Processing file: ".$file." ...\r\n"; convert_file($file);
} print("Done.\r\n");

To run it, you need to create 2 sub-directories ("input" and "output"), then when the script runs he convert all JSON files inside the "input" directory and generate the fixed JSON files in "output" directory.

Related Discussions
...

While this is a neat script, there may have been an easier way! You can run the 3.6 version that was used to write your JSON, do Import Data to bring the JSON into the project, save it as a project file, and then you can open it with 3.8 and export 3.8 JSON. You can also do that from the command line:

Spine -u 3.6.53 -i skeleton-3.6.json -o skeleton.spine
Spine -u 3.8.93 -i skeleton.spine -o skeleton-3.8.json -e export-settings.json