# 16.7 The JSON Format¶

**MOSEK** provides the possibility to read/write problems and solutions in JSON format. The official JSON website http://www.json.org provides plenty of information along with the format definition. JSON is an industry standard for data exchange and JSON files can be easily written and read in most programming languages using dedicated libraries.

**MOSEK** uses two JSON-based formats:

**JTASK**, for storing problem instances together with solutions and parameters. The JTASK format contains the same information as a native**MOSEK**task task format, that is a very close representation of the internal data storage in the task object.You can write a JTASK file specifying the extension

`.jtask`

. When the parameter`MSK_IPAR_WRITE_JSON_INDENTATION`

is set the JTASK file will be indented to slightly improve readability.**JSOL**, for storing solutions and information items.You can write a JSOL solution file using

`writejsonsol`

. When the parameter`MSK_IPAR_WRITE_JSON_INDENTATION`

is set the JSOL file will be indented to slightly improve readability.You can read a JSOL solution into an existing task file using

`readjsonsol`

. Only the`Task/solutions`

section of the data will be taken into consideration.

## 16.7.1 JTASK Specification¶

The JTASK is a dictionary containing the following sections. All sections are optional and can be omitted if irrelevant for the problem.

`$schema`

: JSON schema.`Task/name`

: The name of the task (string).`Task/INFO`

: Information about problem data dimensions and similar. These are treated as hints when reading the file.`numvar`

: number of variables (int32).`numcon`

: number of constraints (int32).`numcone`

: number of cones (int32, deprecated).`numbarvar`

: number of symmetric matrix variables (int32).`numanz`

: number of nonzeros in A (int64).`numsymmat`

: number of matrices in the symmetric matrix storage E (int64).`numafe`

: number of affine expressions in AFE storage (int64).`numfnz`

: number of nonzeros in F (int64).`numacc`

: number of affine conic constraints (ACCs) (int64).`numdjc`

: number of disjunctive constraints (DJCs) (int64).`numdom`

: number of domains (int64).`mosekver`

: MOSEK version (list(int32)).

`Task/data`

: Numerical and structural data of the problem.`var`

: Information about variables. All fields present must have the same length as`bk`

. All or none of`bk`

,`bl`

, and`bu`

must appear.`name`

: Variable names (list(string)).`bk`

: Bound keys (list(string)).`bl`

: Lower bounds (list(double)).`bu`

: Upper bounds (list(double)).`type`

: Variable types (list(string)).

`con`

: Information about linear constraints. All fields present must have the same length as`bk`

. All or none of`bk`

,`bl`

, and`bu`

must appear.`name`

: Constraint names (list(string)).`bk`

: Bound keys (list(string)).`bl`

: Lower bounds (list(double)).`bu`

: Upper bounds (list(double)).

`barvar`

: Information about symmetric matrix variables. All fields present must have the same length as`dim`

.`name`

: Barvar names (list(string)).`dim`

: Dimensions (list(int32)).

`objective`

: Information about the objective.`name`

: Objective name (string).`sense`

: Objective sense (string).`c`

: The linear part \(c\) of the objective as a sparse vector. Both arrays must have the same length.`subj`

: indices of nonzeros (list(int32)).`val`

: values of nonzeros (list(double)).

`cfix`

: Constant term in the objective (double).`Q`

: The quadratic part \(Q^o\) of the objective as a sparse matrix, only lower-triangular part included. All arrays must have the same length.`subi`

: row indices of nonzeros (list(int32)).`subj`

: column indices of nonzeros (list(int32)).`val`

: values of nonzeros (list(double)).

`barc`

: The semidefinite part \(\barC\) of the objective (list). Each element of the list is a list describing one entry \(\barC_j\) using three fields:index \(j\) (int32).

weights of the matrices from the storage \(E\) forming \(\barC_j\) (list(double)).

indices of the matrices from the storage \(E\) forming \(\barC_j\) (list(int64)).

`A`

: The linear constraint matrix \(A\) as a sparse matrix. All arrays must have the same length.`subi`

: row indices of nonzeros (list(int32)).`subj`

: column indices of nonzeros (list(int32)).`val`

: values of nonzeros (list(double)).

`bara`

: The semidefinite part \(\barA\) of the constraints (list). Each element of the list is a list describing one entry \(\barA_{ij}\) using four fields:index \(i\) (int32).

index \(j\) (int32).

weights of the matrices from the storage \(E\) forming \(\barA_{ij}\) (list(double)).

indices of the matrices from the storage \(E\) forming \(\barA_{ij}\) (list(int64)).

`AFE`

: The affine expression storage.`numafe`

: number of rows in the storage (int64).`F`

: The matrix \(F\) as a sparse matrix. All arrays must have the same length.`subi`

: row indices of nonzeros (list(int64)).`subj`

: column indices of nonzeros (list(int32)).`val`

: values of nonzeros (list(double)).

`g`

: The vector \(g\) of constant terms as a sparse vector. Both arrays must have the same length.`subi`

: indices of nonzeros (list(int64)).`val`

: values of nonzeros (list(double)).

`barf`

: The semidefinite part \(\barF\) of the expressions in AFE storage (list). Each element of the list is a list describing one entry \(\barF_{ij}\) using four fields:index \(i\) (int64).

index \(j\) (int32).

weights of the matrices from the storage \(E\) forming \(\barF_{ij}\) (list(double)).

indices of the matrices from the storage \(E\) forming \(\barF_{ij}\) (list(int64)).

`domains`

: Information about domains. All fields present must have the same length as`type`

.`name`

: Domain names (list(string)).`type`

: Description of the type of each domain (list). Each element of the list is a list describing one domain using at least one field:domain type (string).

(except

`pexp`

,`dexp`

) dimension (int64).(only

`ppow`

,`dpow`

) weights (list(double)).

`ACC`

: Information about affine conic constraints (ACC). All fields present must have the same length as`domain`

.`name`

: ACC names (list(string)).`domain`

: Domains (list(int64)).`afeidx`

: AFE indices, grouped by ACC (list(list(int64))).`b`

: constant vectors \(b\), grouped by ACC (list(list(double))).

`DJC`

: Information about disjunctive constraints (DJC). All fields present must have the same length as`termsize`

.`name`

: DJC names (list(string)).`termsize`

: Term sizes, grouped by DJC (list(list(int64))).`domain`

: Domains, grouped by DJC (list(list(int64))).`afeidx`

: AFE indices, grouped by DJC (list(list(int64))).`b`

: constant vectors \(b\), grouped by DJC (list(list(double))).

`MatrixStore`

: The symmetric matrix storage \(E\) (list). Each element of the list is a list describing one entry \(E\) using four fields in sparse matrix format, lower-triangular part only:dimension (int32).

row indices of nonzeros (list(int32)).

column indices of nonzeros (list(int32)).

values of nonzeros (list(double)).

`Q`

: The quadratic part \(Q^c\) of the constraints (list). Each element of the list is a list describing one entry \(Q^c_i\) using four fields in sparse matrix format, lower-triangular part only:the row index \(i\) (int32).

row indices of nonzeros (list(int32)).

column indices of nonzeros (list(int32)).

values of nonzeros (list(double)).

`qcone`

(deprecated). The description of cones. All fields present must have the same length as`type`

.`name`

: Cone names (list(string)).`type`

: Cone types (list(string)).`par`

: Additional cone parameters (list(double)).`members`

: Members, grouped by cone (list(list(int32))).

`Task/solutions`

: Solutions. This section can contain up to three subsections called:`interior`

`basic`

`integer`

corresponding to the three solution types in MOSEK. Each of these sections has the same structure:

`prosta`

: problem status (string).`solsta`

: solution status (string).`xx`

,`xc`

,`y`

,`slc`

,`suc`

,`slx`

,`sux`

,`snx`

: one for each component of the solution of the same name (list(double)).`skx`

,`skc`

,`skn`

: status keys (list(string)).`doty`

: the dual \(\doty\) solution, grouped by ACC (list(list(double))).`barx`

,`bars`

: the primal/dual semidefinite solution, grouped by matrix variable (list(list(double))).

`Task/parameters`

: Parameters.`iparam`

: Integer parameters (dictionary). A dictionary with entries of the form`name:value`

, where`name`

is a shortened parameter name (without leading`MSK_IPAR_`

) and`value`

is either an integer or string if the parameter takes values from an enum.`dparam`

: Double parameters (dictionary). A dictionary with entries of the form`name:value`

, where`name`

is a shortened parameter name (without leading`MSK_DPAR_`

) and`value`

is a double.`sparam`

: String parameters (dictionary). A dictionary with entries of the form`name:value`

, where`name`

is a shortened parameter name (without leading`MSK_SPAR_`

) and`value`

is a string. Note that this section is allowed but MOSEK ignores it both when writing and reading JTASK files.

## 16.7.2 JSOL Specification¶

The JSOL is a dictionary containing the following sections. All sections are optional and can be omitted if irrelevant for the problem.

`$schema`

: JSON schema.`Task/name`

: The name of the task (string).`Task/solutions`

: Solutions. This section can contain up to three subsections called:`interior`

`basic`

`integer`

corresponding to the three solution types in MOSEK. Each of these section has the same structure:

`prosta`

: problem status (string).`solsta`

: solution status (string).`xx`

,`xc`

,`y`

,`slc`

,`suc`

,`slx`

,`sux`

,`snx`

: one for each component of the solution of the same name (list(double)).`skx`

,`skc`

,`skn`

: status keys (list(string)).`doty`

: the dual \(\doty\) solution, grouped by ACC (list(list(double))).`barx`

,`bars`

: the primal/dual semidefinite solution, grouped by matrix variable (list(list(double))).

`Task/information`

: Information items from the optimizer.`int32`

: int32 information items (dictionary). A dictionary with entries of the form`name:value`

.`int64`

: int64 information items (dictionary). A dictionary with entries of the form`name:value`

.`double`

: double information items (dictionary). A dictionary with entries of the form`name:value`

.

## 16.7.3 A `jtask`

example¶

```
{
"$schema":"http://mosek.com/json/schema#",
"Task/name":"Markowitz portfolio with market impact",
"Task/INFO":{"numvar":7,"numcon":1,"numcone":0,"numbarvar":0,"numanz":6,"numsymmat":0,"numafe":13,"numfnz":12,"numacc":4,"numdjc":0,"numdom":3,"mosekver":[10,0,0,3]},
"Task/data":{
"var":{
"name":["1.0","x[0]","x[1]","x[2]","t[0]","t[1]","t[2]"],
"bk":["fx","lo","lo","lo","fr","fr","fr"],
"bl":[1,0.0,0.0,0.0,-1e+30,-1e+30,-1e+30],
"bu":[1,1e+30,1e+30,1e+30,1e+30,1e+30,1e+30],
"type":["cont","cont","cont","cont","cont","cont","cont"]
},
"con":{
"name":["budget[]"],
"bk":["fx"],
"bl":[1],
"bu":[1]
},
"objective":{
"sense":"max",
"name":"obj",
"c":{
"subj":[1,2,3],
"val":[0.1073,0.0737,0.0627]
},
"cfix":0.0
},
"A":{
"subi":[0,0,0,0,0,0],
"subj":[1,2,3,4,5,6],
"val":[1,1,1,0.01,0.01,0.01]
},
"AFE":{
"numafe":13,
"F":{
"subi":[1,1,1,2,2,3,4,6,7,9,10,12],
"subj":[1,2,3,2,3,3,4,1,5,2,6,3],
"val":[0.166673333200005,0.0232190712557243,0.0012599496030238,0.102863378954911,-0.00222873156550421,0.0338148677744977,1,1,1,1,1,1]
},
"g":{
"subi":[0,5,8,11],
"val":[0.035,1,1,1]
}
},
"domains":{
"type":[["r",0],
["quad",4],
["ppow",3,[0.6666666666666666,0.33333333333333337]]]
},
"ACC":{
"name":["risk[]","tz[0]","tz[1]","tz[2]"],
"domain":[1,2,2,2],
"afeidx":[[0,1,2,3],
[4,5,6],
[7,8,9],
[10,11,12]]
}
},
"Task/solutions":{
"interior":{
"prosta":"unknown",
"solsta":"unknown",
"skx":["fix","supbas","supbas","supbas","supbas","supbas","supbas"],
"skc":["fix"],
"xx":[1,0.10331580274282556,0.11673185566457132,0.7724326587076371,0.033208600335718846,0.03988270849469869,0.6788769587942524],
"xc":[1],
"slx":[0.0,-5.585840467641202e-10,-8.945844685006369e-10,-7.815248786428623e-11,0.0,0.0,0.0],
"sux":[0.0,0.0,0.0,0.0,0.0,0.0,0.0],
"snx":[0.0,0.0,0.0,0.0,0.0,0.0,0.0],
"slc":[0.0],
"suc":[-0.046725814048521205],
"y":[0.046725814048521205],
"doty":[[-0.6062603164682975,0.3620818321879349,0.17817754087278295,0.4524390346223723],
[-4.6725842015519993e-4,-7.708781121860897e-6,2.24800624747081e-4],
[-4.6725842015519993e-4,-9.268264309496919e-6,2.390390600079771e-4],
[-4.6725842015519993e-4,-1.5854982159992136e-4,6.159249331148646e-4]]
}
},
"Task/parameters":{
"iparam":{
"LICENSE_DEBUG":"ON",
"MIO_SEED":422
},
"dparam":{
"MIO_MAX_TIME":100
},
"sparam":{
}
}
}
```