DEX read JSON file

  • 28 September 2022
  • 1 reply

Hello AIMMS community,


I am trying to create a mapping file to read a JSON file using Data Exchange Library. The JSON file is structured as follows:

Data: {

"CaseTable": [



            "Specification""Specification 1"




            "Specification""Specification 2"



"PriceTable": [



            "Specification""Specification 1",





            "Specification""Specification 2",




As can be seen, the JSON file includes two tables: "CaseTable" and "PriceTable". I want to read price from PriceTable and assign it to the Price_Parameter(i_case, i_contract) which is indexed over “Case” and “Contract”. For example the value of this parameter should be 200 if the Case 2 and Contract “X” is selected:

Price_Parameter(2, X)=200.

Case 2 is related to the Specification 2 (according to the CaseTable) and the price for Specification 2 is 200 (according to the PriceTable).


Could you please let me know how can I create a mapping file to read this parameter? 




Best answer by MarcelRoelofs 29 September 2022, 12:05

View original

1 reply

Userlevel 4
Badge +5

Hi @Sajad.Karimi 

If I understand you correctly, the price table vector in the json file could also easily contain 6 objects, holding the prices for case 1 and 2, and contracts X, Y and Z. 

I'm a little confused why you want to refer to cases by number in your model, while the prices are in the price table refer to cases by specification. For AIMMS it then makes much more sense to also refer to cases by their specification labels, instead of by number. 

For that case, the mapping becomes extremely straightforward: 



        <ObjectMapping name="Data">

            <ArrayMapping name="CaseTable">


                    <ValueMapping name="Specification" binds-to="case"/>

                    <ValueMapping name="Case" maps-to="CaseNumber(case)"/>



            <ArrayMapping name="PriceTable">


                    <ValueMapping name="Specification" binds-to="case"/>

                    <ValueMapping name="Contract" binds-to="contract"/>

                    <ValueMapping name="Price" maps-to="ContractPrice(case,contract)"/>







The attached model brings it all together. 

If you are really after numbered cases, then I would just read in the prices using a separate index, filled by employing an iterative-binds-to attribute in the mapping file, and map the contract prices obtained in this way onto case numbers by comparing the specification value associated with all prices with the specification value of the cases inside the model. There is no way to do that on-the-fly specification-to-case-number mapping directly using the DEX library.



Didn't find what you were looking for? Try searching on our documentation pages:

AIMMS Developer & PRO | AIMMS How-To | AIMMS SC Navigator