I have the follwoing json structure (see here: https://github.com/sebischair/NLU-Evaluation-Corpora/blob/master/AskUbuntuCorpus.json):
{
"author": "Kristofer",
"url": "http://askubuntu.com/questions/226332/how-to-install-a-canon-mf8040cn-printer-on-ubuntu-12-04",
"text": "How to Install a Canon MF8040Cn Printer on Ubuntu 12.04",
"entities": [
{
"text": "Canon MF8040Cn",
"entity": "Printer",
"stop": 5,
"start": 4
},
{
"text": "12.04",
"entity": "UbuntuVersion",
"stop": 11,
"start": 9
}
],
"intent": "Setup Printer",
"answer": {
"text": "<p>For 14.04 through 16.04 do the following:</p>\n\n<p>Download the drivers from:\n<a href=\"https://www.usa.canon.com/internet/portal/us/home/support/details/printers/black-and-white-laser/mf4770n?tab=drivers#Z7_MQH8HIC0L88RB0AMD0F1Q42K25\" rel=\"nofollow\">https://www.usa.canon.com/internet/portal/us/home/support/details/printers/black-and-white-laser/mf4770n?tab=drivers#Z7_MQH8HIC0L88RB0AMD0F1Q42K25</a></p>\n\n<p>untar it to a directory.\nfrom that directory (assuming 64-bit, adjust as you need to)</p>\n\n<pre><code>cd ~/Downloads\ngunzip -c Linux_UFRII_PrinterDriver_V320_us_EN.tar.gz | tar xvf -\ncd Linux_UFRII_PrinterDriver_V320_us_EN/64-bit_Driver/Debian/\nsudo apt-get -y install libglade2-0 libc6:i386 lib32z1 libxml2:i386 libjpeg62:i386 libstdc++6:i386\ncd 64-bit_Driver/Debian\nsudo dpkg -i *.deb\n</code></pre>\n\n<p>reboot</p>\n\n<p>run add printer .. should just show up automatically when you click the 'Add' button .. give it a few seconds and the printer chirps then just magically shows up.</p>\n\n<p>EDIT 3/2/15 for Vivid (15.04) (I suspect may need for 14.10 as well on brand new installation):</p>\n\n<p>Added extra software dependencies to the above</p>\n\n<p>EDIT 12/18/15 for 15.10 everything worked using above steps. Also, I didn't have to reboot .. it just worked.</p>\n\n<p>EDIT 2/27/16 (16.04beta) Updated the link to the 3.10 driver (they updated their website). Everything just worked using above, didn't need to reboot.</p>\n",
"author": "JimB"
},
"training": false
}
So you can load this as a dictionary with json.load.
I need to change the order of the key vlaue pairs in the entities-dictionary. Now it is text, entity, stop, start. I want to change the order of every pair. Likewise the "intent" after the entities dict I want to to change the position before this entities dict.
collections.OrderedDict?json.loadis a json object, not a dictionary", that's a common misconception. There is no independent "json" type;json.loadreturns a perfectly ordinary dictionary. (or list or string or int, depending on the structure of the data you're loading)