Home Applications Object-based-M-N-to-JSON

Object-based-M-N-to-JSON

This application is not supported by InterSystems Corporation. Please be notified that you use it at your own risk.
5
1 reviews
0
Awards
130
Views
1
IPM installs
3
1
Details
Releases
Reviews  (1)
Issues
This app has a demo View
Sample for object method %JSON.Export for M:N Relationship

What's new in this version

rework optical presentation
use %JOB.Format for display
polish Online demo
clean IPM output

Quality Gate Status

Object-based-M-N-to-JSON

Sample for %JSONExport against a class with N:N Relationship
It is based on the object functionality of %JSON.Adaptor.cls

Prerequisites

Make sure you have git and Docker desktop installed.

Installation

Clone/git pull the repo into any local directory

git https://github.com/rcemper/Object-based-M-N-to-JSON.git

Build the container with your project:

docker compose --progress plain build

Run the container

docker compose up -d

To follow the startup you may use

docker compose logs -f

Testing

After installing this sample, the following two commands can be run from terminal or console

docker-compose exec iris iris session iris    

do ##class(JSONExportManyToMany.TeacherStudent).Populate()

do ##class(JSONExportManyToMany.TeacherStudent).Test()

  • The test output should appear as follows:
{"Name":"Peter","Teachers":[{"ID":1,"Teacher":{"Name":"Teacher1Name"}},{"ID":2,"Teacher":{"Name":"Teacher2Name"}}]}

{
"Name":"Peter",
"Teachers":[
{
"ID":1,
"Teacher":{
"Name":"Teacher1Name"
}
},
{
"ID":2,
"Teacher":{
"Name":"Teacher2Name"
}
}
]
}

{"Name":"Nael","Teachers":[{"ID":3,"Teacher":{"Name":"Teacher1Name"}},{"ID":4,"Teacher":{"Name":"Teacher3Name"}}]}

{
"Name":"Nael",
"Teachers":[
{
"ID":3,
"Teacher":{
"Name":"Teacher1Name"
}
},
{
"ID":4,
"Teacher":{
"Name":"Teacher3Name"
}
}
]
}

{"Name":"Teacher1Name","Students":[{"ID":1,"Student":{"Name":"Peter"}},{"ID":3,"Student":{"Name":"Nael"}}]}

{
"Name":"Teacher1Name",
"Students":[
{
"ID":1,
"Student":{
"Name":"Peter"
}
},
{
"ID":3,
"Student":{
"Name":"Nael"
}
}
]
}

{"Name":"Teacher2Name","Students":[{"ID":2,"Student":{"Name":"Peter"}}]}

{
"Name":"Teacher2Name",
"Students":[
{
"ID":2,
"Student":{
"Name":"Peter"
}
}
]
}

{"Name":"Teacher3Name","Students":[{"ID":4,"Student":{"Name":"Nael"}}]}

{
"Name":"Teacher3Name",
"Students":[
{
"ID":4,
"Student":{
"Name":"Nael"
}
}
]
}

{"Name":"Teacher3Name","Students":[{"ID":4,"Student":{"Name":"Nael"}}]}

{
"Name":"Teacher3Name",
"Students":[
{
"ID":4,
"Student":{
"Name":"Nael"
}
}
]
}
USER>

You will notice here that when exporting from Student (First 2 output lines),
the relationship to Teacher is followed through TeacherStudent and details of the Teacher are exported.

Likewise, when exporting from Teacher, the relationship to Student is followed through
TeacherStudent and details of the Student are exported.

Demo Server SMP
Demo Server WebTerminal

Made with
Install
zpm install object-m-n-to-json download archive
Version
1.0.104 Oct, 2023
ObjectScript quality test
Category
Technology Example
Works with
InterSystems IRISInterSystems IRIS for Health
First published
04 Oct, 2023
Last checked by moderator
01 Nov, 2023Works