You can deserialize a lot of inlined JSON
files in one JSON
file from different sources (local or remote files), like that:
file://
to load file from systemhttp://
andhttps://
to load files from web servers
Use JsonCombiner
instead of JsonSerializer
to deserialize JSON file from file system and inherit each inlined class or struct from IJsonCombine
interface
public TestObject LoadFromFile(string relativePath)
{
string path = Path.Combine(Environment.CurrentDirectory, relativePath);
return JsonCombiner.Deserialize<TestObject>(path, options);
}
Also you can able to make your own json IJsonLoader
variant and register it via JsonCombiner.RegisterLoader
method.
private void Main(string[] args)
{
var myLoader = new MyJsonLoader();
JsonCombiner.RegisterLoader("myhttp", myLoader);
}
Root file:
{
"param1": "param1",
"param2": 2,
"param3": 3.3,
"inner1": "file://inline/inner_object_1.json",
"inner2": "inline/inner_object_2.json",
"inner3": "http://any.public.host.xyz/json.file.json"
}
File inline/inner_object_1.json
:
{
"arg1": "arg1",
"arg2": 44,
"arg3": 55.55
}
File inline/inner_object_2.json
:
{
"arg1": "arg2",
"arg2": 66,
"arg3": 77.77
}