Quantcast
Channel: Liquibase Forums
Viewing all articles
Browse latest Browse all 2993

JSON XML

$
0
0
Bidirectional conversion of JSON <==> XML seems off.

Given the following insert changeSet in JSON from the source:

  1. {
  2.     "databaseChangeLog": [
  3.         {
  4.             "changeSet": {
  5.                 "id": "datatypetest-2",
  6.                 "author": "nvoxland",
  7.                 "validCheckSums": ["ANY"],
  8.                 "changes": [
  9.                     {
  10.                         "insert": {
  11.                             "tableName": "dataTypeTest",
  12.                             "columns": [
  13.                                 {
  14.                                     "column": {
  15.                                         "name": "id",
  16.                                         "valueNumeric": 1
  17.                                     }
  18.                                 },
  19.                                 {
  20.                                     "column": {
  21.                                         "name": "dateCol",
  22.                                         "valueDate": "2007-08-09"
  23.                                     }
  24.                                 },
  25.                                 {
  26.                                     "column": {
  27.                                         "name": "timeCol",
  28.                                         "valueDate": "13:14:15"
  29.                                     }
  30.                                 },
  31.                                 {
  32.                                     "column": {
  33.                                         "name": "dateTimeCol",
  34.                                         "valueDate": "2007-08-09T13:14:15"
  35.                                     }
  36.                                 },
  37.                                 {
  38.                                     "column": {
  39.                                         "name": "bigintcol",
  40.                                         "valueNumeric": 2
  41.                                     }
  42.                                 }
  43.                             ]
  44.                         }
  45.                     },
  46.                     {
  47.                         "insert": {
  48.                             "tableName": "dataTypeTest",
  49.                             "columns": [
  50.                                 {
  51.                                     "column": {
  52.                                         "name": "id",
  53.                                         "valueNumeric": 2
  54.                                     }
  55.                                 },
  56.                                 {
  57.                                     "column": {
  58.                                         "name": "dateCol",
  59.                                         "valueDate": "current_datetime"
  60.                                     }
  61.                                 },
  62.                                 {
  63.                                     "column": {
  64.                                         "name": "timeCol",
  65.                                         "valueComputed": "current_datetime"
  66.                                     }
  67.                                 },
  68.                                 {
  69.                                     "column": {
  70.                                         "name": "dateTimeCol",
  71.                                         "valueDate": "current_datetime"
  72.                                     }
  73.                                 },
  74.                                 {
  75.                                     "column": {
  76.                                         "name": "bigintcol",
  77.                                         "valueNumeric": 2
  78.                                     }
  79.                                 }
  80.                             ]
  81.                         }
  82.                     }
  83.                 ]
  84.             }
  85.         }
  86.     ]
  87. }

When converted to XML using a the JQuery json2xml converter (and others), turns into the following XML
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <databaseChangeLog>
  3.   <changeSet>
  4.     <validCheckSums>ANY</validCheckSums>
  5.     <id>datatypetest-2</id>
  6.     <author>nvoxland</author>
  7.     <changes>
  8.       <insert>
  9.         <tableName>dataTypeTest</tableName>
  10.         <columns>
  11.           <column>
  12.             <valueNumeric>1</valueNumeric>
  13.             <name>id</name>
  14.           </column>
  15.         </columns>
  16.         <columns>
  17.           <column>
  18.             <name>dateCol</name>
  19.             <valueDate>2007-08-09</valueDate>
  20.           </column>
  21.         </columns>
  22.         <columns>
  23.           <column>
  24.             <name>timeCol</name>
  25.             <valueDate>13:14:15</valueDate>
  26.           </column>
  27.         </columns>
  28.         <columns>
  29.           <column>
  30.             <name>dateTimeCol</name>
  31.             <valueDate>2007-08-09T13:14:15</valueDate>
  32.           </column>
  33.         </columns>
  34.         <columns>
  35.           <column>
  36.             <valueNumeric>2</valueNumeric>
  37.             <name>bigintcol</name>
  38.           </column>
  39.         </columns>
  40.       </insert>
  41.     </changes>
  42.     <changes>
  43.       <insert>
  44.         <tableName>dataTypeTest</tableName>
  45.         <columns>
  46.           <column>
  47.             <valueNumeric>2</valueNumeric>
  48.             <name>id</name>
  49.           </column>
  50.         </columns>
  51.         <columns>
  52.           <column>
  53.             <name>dateCol</name>
  54.             <valueDate>current_datetime</valueDate>
  55.           </column>
  56.         </columns>
  57.         <columns>
  58.           <column>
  59.             <name>timeCol</name>
  60.             <valueComputed>current_datetime</valueComputed>
  61.           </column>
  62.         </columns>
  63.         <columns>
  64.           <column>
  65.             <name>dateTimeCol</name>
  66.             <valueDate>current_datetime</valueDate>
  67.           </column>
  68.         </columns>
  69.         <columns>
  70.           <column>
  71.             <valueNumeric>2</valueNumeric>
  72.             <name>bigintcol</name>
  73.           </column>
  74.         </columns>
  75.       </insert>
  76.     </changes>
  77.   </changeSet>
  78. </databaseChangeLog>
And the same insert changeSet in XML from the source:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.0.xsd         http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
  3.   <changeSet author="nvoxland" id="datatypetest-2">
  4.     <validCheckSum>ANY</validCheckSum>
  5.     <insert tableName="dataTypeTest">
  6.       <column name="id" valueNumeric="1"/>
  7.       <column name="dateCol" valueDate="2007-08-09"/>
  8.       <column name="timeCol" valueDate="13:14:15"/>
  9.       <column name="dateTimeCol" valueDate="2007-08-09T13:14:15"/>
  10.       <column name="bigintcol" valueNumeric="2"/>
  11.     </insert>
  12.     <insert dbms="!derby" tableName="dataTypeTest">
  13.       <column name="id" valueNumeric="2"/>
  14.       <column name="dateCol" valueDate="current_datetime"/>
  15.       <column name="timeCol" valueComputed="current_datetime"/>
  16.       <column name="dateTimeCol" valueDate="current_datetime"/>
  17.       <column name="bigintcol" valueNumeric="2"/>
  18.     </insert>
  19.   </changeSet>
  20. </databaseChangeLog>

When converted using the JQuery xml2json, produces the following JSON:

  1. {
  2.   "databaseChangeLog": {
  3.     "changeSet": {
  4.       "author": "nvoxland",
  5.       "id": "datatypetest-2",
  6.       "validCheckSum": "ANY",
  7.       "insert": [
  8.         {
  9.           "tableName": "dataTypeTest",
  10.           "column": [
  11.             {
  12.               "name": "id",
  13.               "valueNumeric": "1"
  14.             },
  15.             {
  16.               "name": "dateCol",
  17.               "valueDate": "2007-08-09"
  18.             },
  19.             {
  20.               "name": "timeCol",
  21.               "valueDate": "13:14:15"
  22.             },
  23.             {
  24.               "name": "dateTimeCol",
  25.               "valueDate": "2007-08-09T13:14:15"
  26.             },
  27.             {
  28.               "name": "bigintcol",
  29.               "valueNumeric": "2"
  30.             }
  31.           ]
  32.         },
  33.         {
  34.           "dbms": "!derby",
  35.           "tableName": "dataTypeTest",
  36.           "column": [
  37.             {
  38.               "name": "id",
  39.               "valueNumeric": "2"
  40.             },
  41.             {
  42.               "name": "dateCol",
  43.               "valueDate": "current_datetime"
  44.             },
  45.             {
  46.               "name": "timeCol",
  47.               "valueComputed": "current_datetime"
  48.             },
  49.             {
  50.               "name": "dateTimeCol",
  51.               "valueDate": "current_datetime"
  52.             },
  53.             {
  54.               "name": "bigintcol",
  55.               "valueNumeric": "2"
  56.             }
  57.           ]
  58.         }
  59.       ]
  60.     }
  61.   }
  62. }

I'm confused by this apparent discrepancy. It seems to prevent automated conversions from one format to another, which seems like a natural option given the relative compatibility of JSON, XML and YAML. I recognize that there are well-known problems with these conversions, but those don't seem to be what is at play here.

I'd love to understand the thinking on this - it looks to me that you implemented YAML and got JSON, rather than deriving from your original XML structure.

Viewing all articles
Browse latest Browse all 2993

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>