Using diff via Java API

Your snapshot file looks fine.

I spent some time today stepping through scenarios in the CLI and in my own simplified program and I believe I have something for you to try. I don’t think the offline database specification works with absolute paths. I saw the same errors that you described when I was using the CLI with absolute paths. When I switched to relative paths the diff command works.

➜  ~ liquibase diff --reference-url="offline:json?snapshot=/Users/ppickerill/tmp/snap1.json" --url="offline:json?snapshot=/Users/ppickerill/tmp/snap1.json"
####################################################
##   _     _             _ _                      ##
##  | |   (_)           (_) |                     ##
##  | |    _  __ _ _   _ _| |__   __ _ ___  ___   ##
##  | |   | |/ _` | | | | | '_ \ / _` / __|/ _ \  ##
##  | |___| | (_| | |_| | | |_) | (_| \__ \  __/  ##
##  \_____/_|\__, |\__,_|_|_.__/ \__,_|___/\___|  ##
##              | |                               ##
##              |_|                               ##
##                                                ##
##  Get documentation at docs.liquibase.com       ##
##  Get certified courses at learn.liquibase.com  ##
##                                                ##
####################################################
Starting Liquibase at 15:30:14 using Java 21.0.6 (version 4.31.0 #6261 built at 2025-01-14 14:24+0000)
Liquibase Version: 4.31.0
Liquibase Open Source 4.31.0 by Liquibase
ERROR: Exception Details
ERROR: Exception Primary Class:  UnexpectedLiquibaseException
ERROR: Exception Primary Reason:  Resource does not exist
ERROR: Exception Primary Source:  4.31.0

Unexpected error running Liquibase: Cannot parse snapshot offline:json?snapshot=/Users/ppickerill/tmp/snap1.json
  - Caused by: Resource does not exist

For more information, please use the --log-level flag
➜  ~ liquibase diff --reference-url="offline:json?snapshot=tmp/snap1.json" --url="offline:json?snapshot=tmp/snap1.json"
####################################################
##   _     _             _ _                      ##
##  | |   (_)           (_) |                     ##
##  | |    _  __ _ _   _ _| |__   __ _ ___  ___   ##
##  | |   | |/ _` | | | | | '_ \ / _` / __|/ _ \  ##
##  | |___| | (_| | |_| | | |_) | (_| \__ \  __/  ##
##  \_____/_|\__, |\__,_|_|_.__/ \__,_|___/\___|  ##
##              | |                               ##
##              |_|                               ##
##                                                ##
##  Get documentation at docs.liquibase.com       ##
##  Get certified courses at learn.liquibase.com  ##
##                                                ##
####################################################
Starting Liquibase at 15:30:33 using Java 21.0.6 (version 4.31.0 #6261 built at 2025-01-14 14:24+0000)
Liquibase Version: 4.31.0
Liquibase Open Source 4.31.0 by Liquibase

Diff Results:
Reference Database: null @ offline:json?snapshot=tmp/snap1.json (Default Schema: test)
Comparison Database: null @ offline:json?snapshot=tmp/snap1.json (Default Schema: test)
Compared Schemas: test
Product Name: EQUAL
Product Version: EQUAL
Missing Catalog(s): NONE
Unexpected Catalog(s): NONE
Changed Catalog(s): NONE
Missing Column(s): NONE
Unexpected Column(s): NONE
Changed Column(s): NONE
Missing Foreign Key(s): NONE
Unexpected Foreign Key(s): NONE
Changed Foreign Key(s): NONE
Missing Index(s): NONE
Unexpected Index(s): NONE
Changed Index(s): NONE
Missing Primary Key(s): NONE
Unexpected Primary Key(s): NONE
Changed Primary Key(s): NONE
Missing Table(s): NONE
Unexpected Table(s): NONE
Changed Table(s): NONE
Missing Unique Constraint(s): NONE
Unexpected Unique Constraint(s): NONE
Changed Unique Constraint(s): NONE
Missing View(s): NONE
Unexpected View(s): NONE
Changed View(s): NONE
Liquibase command 'diff' was executed successfully.

To use relative paths with my java program, I copied the snapshot files to the directory where my class files were compiled and just referenced them by name. I’ve zipped that project up here.

Good luck!