https://github.com/pixelbyaj/iso20022.xsd
ISO20022.XSD is a powerful dotnet library to convert ISO20022 XSD to JSON.
https://github.com/pixelbyaj/iso20022.xsd
Last synced: 3 months ago
JSON representation
ISO20022.XSD is a powerful dotnet library to convert ISO20022 XSD to JSON.
- Host: GitHub
- URL: https://github.com/pixelbyaj/iso20022.xsd
- Owner: pixelbyaj
- License: apache-2.0
- Created: 2024-10-16T11:46:41.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2024-10-16T14:54:12.000Z (7 months ago)
- Last Synced: 2025-01-17T07:08:11.146Z (4 months ago)
- Size: 9.77 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Xsd To Json Converter
[](https://www.nuget.org/packages/XSDService/)## This will help to convert any XSD to JSON
## Install package
1. Install the `XSDService` NuGet package.
* .NET CLI
```cs
dotnet add package XSDService --version 1.1.4
```
* PackageManager
```cs
Install-Package XSDService -Version 1.1.4
```## Usage
```C#
using XSDService;var fileInfo = new FileInfo(fileName);
if (File.Exists(fileName) && fileInfo.Extension.Equals(".xsd"))
{
XsdToJson xsdLib = new(fileName);
xsdLib.Convert();
File.AppendAllText(fileInfo.FullName.Replace(".xsd", ".json"), xsdLib.SchemaJson);
}
```
## Model of JSON
```cs
public class XsdSchema
{
public string Namespace { get; set; }
public SchemaElement SchemaElement { get; set; }
}public class SchemaElement
{
public string Id { get; set; }
public string Name { get; set; }
public string DataType { get; set; }
public string MinOccurs { get; set; }
public string MaxOccurs { get; set; }
public string MinLength { get; set; }
public string MaxLength { get; set; }
public string Pattern { get; set; }
public string FractionDigits { get; set; }
public string TotalDigits { get; set; }
public string MinExclusive { get; set; }
public string MaxExclusive { get; set; }
public string MinInclusive { get; set; }
public string MaxInclusive { get; set; }
public string[] Values { get; set; }
public bool IsCurrency { get; set; }
public string XPath { get; set; }
public List Elements { get; set; }
}
```
### Example
```json
{
"namespace": "urn:iso:std:iso:20022:tech:xsd:camt.053.001.10",
"schemaElement": {
"id": "Document",
"name": "Document",
"dataType": null,
"minOccurs": "1",
"maxOccurs": null,
"minLength": null,
"maxLength": null,
"pattern": null,
"fractionDigits": null,
"totalDigits": null,
"minInclusive": null,
"maxInclusive": null,
"values": null,
"isCurrency": false,
"xpath": "Document",
"elements":[
...
]
}
}
```## Changes
## Version 1.3.6 release
* MinExclusive & MaxExclusive included in new release.
## Version 1.3.5 release
* Throw JsonException the case where it found deep nested node structure.
* CurrentDepth (64) is equal to or larger than the maximum allowed depth of (64)
## Usage## Usage
```c#
using XSDService;
string targetNamespace = "urn:iso:std:iso:20022:tech:xsd:camt.053.001.10";
string jsonData = File.ReadAllText(@jsonPath);
string xsdContent = File.ReadAllText(@xsdFilePath);
XElement xml = Iso20022.Convert(jsonData, targetNamespace) ?? throw new Exception("Conversion failed");
if (Iso20022.ValidateMXMessage(xsdContent, xml.ToString(), out string validationMessage))
{
if (string.IsNullOrEmpty(validationMessage))
{
Console.WriteLine(xml?.ToString());
}
else
{
Console.Error.WriteLine(validationMessage);
}
}
```
### Example```json
{
"Document": {
"Document_BkToCstmrStmt": {
"Document_BkToCstmrStmt_GrpHdr": {
"Document_BkToCstmrStmt_GrpHdr_MsgId": "235549650",
"Document_BkToCstmrStmt_GrpHdr_CreDtTm": "2023-10-05T14:43:51.979",
"Document_BkToCstmrStmt_GrpHdr_MsgRcpt": {
"Document_BkToCstmrStmt_GrpHdr_MsgRcpt_Nm": "Test Client Ltd.",
"Document_BkToCstmrStmt_GrpHdr_MsgRcpt_Id": {
"Document_BkToCstmrStmt_GrpHdr_MsgRcpt_Id_OrgId": {
"Document_BkToCstmrStmt_GrpHdr_MsgRcpt_Id_OrgId_Othr": [
{
"Document_BkToCstmrStmt_GrpHdr_MsgRcpt_Id_OrgId_Othr_Id": "test001"
}
]
}
}
},
"Document_BkToCstmrStmt_GrpHdr_AddtlInf": "AddTInf"
},
"Document_BkToCstmrStmt_Stmt": [
{
"Document_BkToCstmrStmt_Stmt_Id": "258158850",
"Document_BkToCstmrStmt_Stmt_ElctrncSeqNb": "1",
"Document_BkToCstmrStmt_Stmt_LglSeqNb": "1",
"Document_BkToCstmrStmt_Stmt_CreDtTm": "2023-10-05T14:43:52.098",
"Document_BkToCstmrStmt_Stmt_FrToDt": {
"Document_BkToCstmrStmt_Stmt_FrToDt_FrDtTm": "2023-09-30T20:00:00.000",
"Document_BkToCstmrStmt_Stmt_FrToDt_ToDtTm": "2023-10-01T19:59:59.000"
},
"Document_BkToCstmrStmt_Stmt_Acct": {
"Document_BkToCstmrStmt_Stmt_Acct_Tp": {
"Document_BkToCstmrStmt_Stmt_Acct_Tp_Prtry": "IBDA_DDA"
},
"Document_BkToCstmrStmt_Stmt_Acct_Ccy": "USD",
"Document_BkToCstmrStmt_Stmt_Acct_Nm": "Sample Name 123",
"Document_BkToCstmrStmt_Stmt_Acct_Svcr": {
"Document_BkToCstmrStmt_Stmt_Acct_Svcr_FinInstnId": {
"Document_BkToCstmrStmt_Stmt_Acct_Svcr_FinInstnId_BICFI": "GSCRUS30",
"Document_BkToCstmrStmt_Stmt_Acct_Svcr_FinInstnId_Nm": "Goldman Sachs Bank"
}
}
},
"Document_BkToCstmrStmt_Stmt_Bal": [
{
"Document_BkToCstmrStmt_Stmt_Bal_Tp": {
"Document_BkToCstmrStmt_Stmt_Bal_Tp_CdOrPrtry": {
"Document_BkToCstmrStmt_Stmt_Bal_Tp_CdOrPrtry_Cd": "OPBD"
}
},
"Document_BkToCstmrStmt_Stmt_Bal_Amt": {
"Document_BkToCstmrStmt_Stmt_Bal_Amt_Ccy": "USD",
"Document_BkToCstmrStmt_Stmt_Bal_Amt_Amt": "843686.20"
},
"Document_BkToCstmrStmt_Stmt_Bal_CdtDbtInd": "DBIT",
"Document_BkToCstmrStmt_Stmt_Bal_Dt": {
"Document_BkToCstmrStmt_Stmt_Bal_Dt_DtTm": "2023-09-30T20:00:00.000"
}
},
{
"Document_BkToCstmrStmt_Stmt_Bal_Tp": {
"Document_BkToCstmrStmt_Stmt_Bal_Tp_CdOrPrtry": {
"Document_BkToCstmrStmt_Stmt_Bal_Tp_CdOrPrtry_Cd": "CLAV"
}
},
"Document_BkToCstmrStmt_Stmt_Bal_Amt": {
"Document_BkToCstmrStmt_Stmt_Bal_Amt_Ccy": "USD",
"Document_BkToCstmrStmt_Stmt_Bal_Amt_Amt": "334432401.27"
},
"Document_BkToCstmrStmt_Stmt_Bal_CdtDbtInd": "CRDT",
"Document_BkToCstmrStmt_Stmt_Bal_Dt": {
"Document_BkToCstmrStmt_Stmt_Bal_Dt_DtTm": "2023-10-01T23:59:00.000Z"
}
}
]
}
]
}
}
}
```
After Conversion
```xml
235549650
2023-10-05T14:43:51.979
Test Client Ltd.
test001
AddTInf
258158850
1
1
2023-10-05T14:43:52.098
2023-09-30T20:00:00.000
2023-10-01T19:59:59.000
IBDA_DDA
USD
Sample Name 123
GSCRUS30
Goldman Sachs Bank
OPBD
843686.20
DBIT
2023-09-30T20:00:00.000
CLAV
334432401.27
CRDT
2023-10-01T23:59:00.000Z
```