How to extract tables and images from website's json object? - json

"table-wrap": {
"#id": "ams2322-tbl-0001",
"#xml:lang": "en",
"#orientation": "portrait",
"#position": "float",
"label": "Table 1",
"caption": {
"p": "Strength of recomendations"
},
"table": {
"#frame": "hsides",
"#rules": "groups",
"col": [
{
"#style": "border-right:solid 1px #000000",
"#span": "1"
},
{
"#style": "border-right:solid 1px #000000",
"#span": "1"
},
{
"#style": "border-right:solid 1px #000000",
"#span": "1"
},
{
"#style": "border-right:solid 1px #000000",
"#span": "1"
},
{
"#style": "border-right:solid 1px #000000",
"#span": "1"
}
],
"thead": {
"#valign": "top",
"tr": {
"#style": "border-bottom:solid 1px #000000",
"th": [
{
"#align": "left",
"#valign": "top",
"#rowspan": "1",
"#colspan": "1",
"#text": "Strength of Recommendation"
},
{
"#align": "left",
"#valign": "top",
"#rowspan": "1",
"#colspan": "1",
"#text": "Recommend (1)"
},
{
"#align": "left",
"#valign": "top",
"#rowspan": "1",
"#colspan": "1",
"#text": "Suggest (2)"
},
{
"#align": "left",
"#valign": "top",
"#rowspan": "1",
"#colspan": "1",
"#text": "Suggest against (2)"
},
{
"#align": "left",
"#valign": "top",
"#rowspan": "1",
"#colspan": "1",
"#text": "Recommend against (1)"
}
]
}
},
"tbody": {
"tr": [
{
"td": [
{
"#align": "left",
"#rowspan": "1",
"#colspan": "1",
"#text": "Content of recommendation"
},
{
"#align": "left",
"#rowspan": "1",
"#colspan": "1",
"#text": "Strong recommendation in support of an intervention"
},
{
"#align": "left",
"#rowspan": "1",
"#colspan": "1",
"#text": "(Weak) Suggestion in support of an intervention under certain conditions"
},
{
"#align": "left",
"#rowspan": "1",
"#colspan": "1",
"#text": "(Weak) Suggestion against an intervention under certain conditions"
},
{
"#align": "left",
"#rowspan": "1",
"#colspan": "1",
"#text": "Strong recommendation against an intervention"
}
]
},
{
"td": [
{
"#align": "left",
"#rowspan": "1",
"#colspan": "1",
"#text": "Wording of recommendation"
},
{
"#align": "left",
"#rowspan": "1",
"#colspan": "1",
"#text": "We recommend\u2014[intervention]"
},
{
"#align": "left",
"#rowspan": "1",
"#colspan": "1",
"#text": "We suggest\u2014[intervention]"
},
{
"#align": "left",
"#rowspan": "1",
"#colspan": "1",
"#text": "We suggest against\u2014[intervention]"
},
{
"#align": "left",
"#rowspan": "1",
"#colspan": "1",
"#text": "\u2014We recommend against [intervention]"
}
]
}
]
}
},
"permissions": {
"copyright-holder": "John Wiley & Sons, Ltd"
}
}
Hi, I want to extract tables from json object and format them dataframe.
For example this table wrap is one of the table of the article and I want to make it as real table for printing. But I don't know how can I do that. Do you have any idea have can I do that?
And also same thing for figures and images..
Thank you

Related

Mocked operation performance in Azure API Management

I have an Azure API Management API composed of only mocked operations. Most, like the bottom of the attached image, run in the tenths of a ms. However, one that is test/plain coming in and returns application/json typically runs in tens of seconds (top of image). I find this using developer console or calling from Logic Apps. My case has 1.7K coming in, the returned JSON is large-ish at 26K.
Still this great amount of response time seems excessive. Might there be an explanation for it?
My Representation example returned by the mock
{
"FunctionalGroup": {
"TransactionSet": {
"#controlNumber": "270001",
"Area": [
{
"Segment": [
{
"#id": "BEG",
"Element": [
{
"#pos": "1",
"#text": "00"
},
{
"#pos": "2",
"#text": "SA"
},
{
"#pos": "3",
"#text": "86816853"
},
{
"#pos": "5",
"#date": "2015-04-09",
"#text": "20150409"
}
]
},
{
"#id": "REF",
"Element": [
{
"#pos": "1",
"#text": "DP"
},
{
"#pos": "2",
"#text": "16"
},
{
"#pos": "3",
"#text": "DEPARTMENTA"
}
]
}
],
"SegmentLoop": [
{
"#id": "N9",
"#name": "N9",
"Segment": [
{
"#id": "N9",
"Element": [
{
"#pos": "1",
"#text": "ST"
},
{
"#pos": "2",
"#text": "001"
}
]
},
{
"#id": "DTM",
"Element": [
{
"#pos": "1",
"#text": "010"
},
{
"#pos": "2",
"#date": "2015-04-12",
"#text": "20150412"
},
{
"#pos": "3",
"#time": "00:00:00",
"#text": "0000"
}
]
},
{
"#id": "DTM",
"Element": [
{
"#pos": "1",
"#text": "002"
},
{
"#pos": "2",
"#date": "2015-04-12",
"#text": "20150412"
},
{
"#pos": "3",
"#time": "12:34:34",
"#text": "123456"
}
]
},
{
"#id": "DTM",
"Element": [
{
"#pos": "1",
"#text": "001"
},
{
"#pos": "2",
"#date": "2015-04-30",
"#text": "20150430"
},
{
"#pos": "3",
"#time": "12:34:34.789",
"#text": "123456789"
}
]
}
]
},
{
"#id": "N1",
"#name": "N1",
"Segment": [
{
"#id": "N1",
"Element": [
{
"#pos": "1",
"#text": "ST"
},
{
"#pos": "2",
"#text": "COMPANY INC."
},
{
"#pos": "3",
"#text": "92"
},
{
"#pos": "4",
"#text": "001"
}
]
},
{
"#id": "N3",
"Element": [
{
"#pos": "1",
"#text": "123 main street"
},
{
"#pos": "2",
"#text": "PH:(644)123-4567"
}
]
},
{
"#id": "N4",
"Element": [
{
"#pos": "1",
"#text": "Elk Grove Village"
},
{
"#pos": "2",
"#text": "IL"
},
{
"#pos": "3",
"#text": "6007"
},
{
"#pos": "4",
"#text": "US"
}
]
}
]
},
{
"#id": "N1",
"#name": "N1",
"Segment": [
{
"#id": "N1",
"Element": [
{
"#pos": "1",
"#text": "SF"
},
{
"#pos": "2",
"#text": "EDGE ENTERPRISES"
},
{
"#pos": "3",
"#text": "92"
},
{
"#pos": "4",
"#text": "99999"
}
]
},
{
"#id": "N3",
"Element": [
{
"#pos": "1",
"#text": "2645 W. Coast Highway"
}
]
},
{
"#id": "N4",
"Element": [
{
"#pos": "1",
"#text": "Silicon Valley"
},
{
"#pos": "2",
"#text": "CA"
},
{
"#pos": "3",
"#text": "56874"
},
{
"#pos": "4",
"#text": "US"
}
]
}
]
}
]
},
{
"SegmentLoop": [
{
"#id": "PO1",
"#name": "PO1",
"Segment": [
{
"#id": "PO1",
"Element": [
{
"#pos": "1",
"#text": "1"
},
{
"#pos": "2",
"#text": "96"
},
{
"#pos": "3",
"#text": "EA"
},
{
"#pos": "4",
"#text": "2.05"
},
{
"#pos": "6",
"#text": "BP"
},
{
"#pos": "7",
"#text": "HB-Natural Adult Bat"
}
]
}
],
"SegmentLoop": [
{
"#id": "PID",
"#name": "PID",
"Segment": [
{
"#id": "PID",
"Element": [
{
"#pos": "1",
"#text": "F"
},
{
"#pos": "5",
"#text": "DESCRIPTION"
}
]
}
]
}
]
}
]
},
{
"SegmentLoop": [
{
"#id": "CTT",
"#name": "CTT",
"Segment": [
{
"#id": "CTT",
"Element": [
{
"#pos": "1",
"#text": "6"
}
]
},
{
"#id": "AMT",
"Element": [
{
"#pos": "1",
"#text": "TT"
},
{
"#pos": "2",
"#number": "1000.00",
"#text": "100000"
}
]
}
]
}
]
}
]
}
}
}
My Policy in effect for the relevant API op
<policies>
<inbound>
<!--base: Begin Global scope-->
<!-- PC-1404 -->
<set-query-parameter name="subscription-key" exists-action="delete" />
<!--base: End Global scope-->
</inbound>
<backend>
<!--base: Begin Global scope-->
<forward-request />
<!--base: End Global scope-->
</backend>
<outbound>
<mock-response status-code="200" content-type="application/json" />
</outbound>
<on-error>
<!--base: Begin Global scope-->
<!-- By placing policy statements in the on-error section you can review the error by
using the context.LastError property, inspect and customize the error response using the
set-body policy, and configure what happens if an error occurs.
There are error codes for built-in steps and for errors that may occur during the processing of
policy statements.
For more information, see https://msdn.microsoft.com/en-us/library/azure/mt629506.aspx
statements to be applied if there is an error condition go here -->
<!-- for CORS support to Office Add-In to detect subscription key errors, etc. PLEX-JIRA: PC-725 TSCH 8/16/16 -->
<set-header name="Access-Control-Allow-Origin" exists-action="override">
<value>*</value>
</set-header>
<!--base: End Global scope-->
</on-error>
I found I needed to move the mock call up to the inbound section. It was the forward to back end (I actually don't have a backend figured that was taking the time). The new op policy is
<policies>
<inbound>
<mock-response status-code="200" content-type="application/json" />
<base />
</inbound>
<backend>
<base />
</backend>
<outbound>
<base />
</outbound>
<on-error>
<base />
</on-error>

How to change bar opacity upon click of FusionCharts 2D Column Chart?

I am attempting to toggle the opacity of a bar when it is clicked on utilizing the "dataPlotClick" event. I am able to change the opacity, but as soon as I move my mouse off of the bar the opacity changes back to the default.
NOTE: A similar question has been asked before on SO, but doesn't seem to have a valid answer.
How do I utilize the below dataPlotClick event to achieve this?
events: {
"dataPlotClick": function (evtObj, argObj) {
var i, plotItems;
plotItems = evtObj.sender.jsVars.hcObj.elements.plots[0].items;
plotItems[argObj.dataIndex].graphic.attr("fill-opacity", .2);
}
}
Fusion Chart:
FusionCharts.ready(function () {
var revenueChart = new FusionCharts({
type: 'column2d',
renderAt: 'chart-container',
width: '500',
height: '350',
dataFormat: 'json',
dataSource: {
"chart": {
"caption": "Monthly revenue for last year",
"subCaption": "Harry's SuperMart",
"xAxisName": "Month",
"yAxisName": "Revenue (In USD)",
"numberPrefix": "$",
"paletteColors": "#0075c2",
"bgColor": "#ffffff",
"borderAlpha": "20",
"canvasBorderAlpha": "0",
"usePlotGradientColor": "0",
"plotBorderAlpha": "10",
"placevaluesInside": "1",
"rotatevalues": "1",
"valueFontColor": "#ffffff",
"showXAxisLine": "1",
"xAxisLineColor": "#999999",
"divlineColor": "#999999",
"divLineIsDashed": "1",
"showAlternateHGridColor": "0",
"subcaptionFontBold": "0",
"subcaptionFontSize": "14"
},
"data": [
{
"label": "Jan",
"value": "420000"
}, {
"label": "Feb",
"value": "810000"
}, {
"label": "Mar",
"value": "720000"
}, {
"label": "Apr",
"value": "550000"
}, {
"label": "May",
"value": "910000"
}, {
"label": "Jun",
"value": "510000"
}, {
"label": "Jul",
"value": "680000"
}, {
"label": "Aug",
"value": "620000"
}, {
"label": "Sep",
"value": "610000"
}, {
"label": "Oct",
"value": "490000"
}, {
"label": "Nov",
"value": "900000"
}, {
"label": "Dec",
"value": "730000"
}]
},
events: {
"dataPlotClick": function (evtObj, argObj) {
var i, plotItems, plotLength;
plotItems = evtObj.sender.jsVars.hcObj.elements.plots[0].items;
plotItems[argObj.dataIndex].graphic.attr("fill-opacity", .2);
}
}
}
}).render();
});
The alpha attribute need to set within the dataPlotClick FusionCharts API event for the particular data plot which has been clicked.
The particular data plot index could be found with the help of dataObj parameters dataIndex attribute within dataPlotClick FusionCharts API event.
Finally set the modified JSON structure with the help of FusionCharts setJSONData API method.
Please implement the below given code.
FusionCharts.ready(function () {
var topStores = new FusionCharts({
type: 'column2d',
renderAt: 'chart-container',
width: '400',
height: '300',
dataFormat: 'json',
dataSource: {
"chart": {
"caption": "Monthly revenue for last year",
"subCaption": "Harry's SuperMart",
"xAxisName": "Month",
"yAxisName": "Revenue (In USD)",
"numberPrefix": "$",
"paletteColors": "#0075c2",
"bgColor": "#ffffff",
"borderAlpha": "20",
"canvasBorderAlpha": "0",
"usePlotGradientColor": "0",
"plotBorderAlpha": "10",
"placevaluesInside": "1",
"rotatevalues": "1",
"valueFontColor": "#ffffff",
"showXAxisLine": "1",
"xAxisLineColor": "#999999",
"divlineColor": "#999999",
"divLineIsDashed": "1",
"showAlternateHGridColor": "0",
"subcaptionFontBold": "0",
"subcaptionFontSize": "14"
},
"data": [{
"label": "Jan",
"value": "420000"
}, {
"label": "Feb",
"value": "810000"
}, {
"label": "Mar",
"value": "720000"
}, {
"label": "Apr",
"value": "550000"
}, {
"label": "May",
"value": "910000"
}, {
"label": "Jun",
"value": "510000"
}, {
"label": "Jul",
"value": "680000"
}, {
"label": "Aug",
"value": "620000"
}, {
"label": "Sep",
"value": "610000"
}, {
"label": "Oct",
"value": "490000"
}, {
"label": "Nov",
"value": "900000"
}, {
"label": "Dec",
"value": "730000"
}]
},
events: {
"dataPlotClick": function(evtObj, argObj) {
var plotNum= argObj.dataIndex;
var data =evtObj.sender.args.dataSource.data;
data[plotNum].alpha="10";
evtObj.sender.setJSONData(evtObj.sender.args.dataSource);
}
}
})
.render();
});

How to show the trendline in half portion of an msline fusion chart?

Screen Shot
window.renderScoreCardCharts = function(param) {
//if( FusionCharts( "chartContainerFive" ) ) FusionCharts( "chartContainerFive" ).dispose();
for(var i=0;i<=5;i++){
var chartContainerFive = new FusionCharts(
{
/*"id": "scoreCardContainerBarId"+i,
"type" : "MSSPLine",
"type" : "MSLine",
"renderAt" : "scoreCardContainerBar"+i,
"width" : "100%",
"height" : "120px",
"dataFormat" : "json",*/
"id": "scoreCardContainerBarId"+i,
"renderAt" : "scoreCardContainerBar"+i,
"type": 'msline',
"width" : "100%",
"height" : "120px",
"dataFormat": 'json',
"dataSource" : {
"chart": {"caption": arr[i],
"captionFontSize" : "12",
"captionFontColor" : "#8a807c",
"captionFontBold" : "1",
"showLegend" : "0",
"bgcolor" : "FFFFFF",
"drawAnchors":"0",
"showalternatehgridcolor" : "1",
"showValues" : "0",
"canvasborderalpha" : "0",
//"legendposition" : "right",
"legendshadow" : "0",
"legendborderalpha" : "0",
"palettecolors" : "#f8bd19,#008ee4,#33bdda,#e44a00,#6baa01,#583e78",
"exportEnabled" : "0",
"exportFileName" : "QCDDMSESChange",
"showToolTipShadow" : "1",
"toolTipBorderRadius" : "6",
"canvasbgAlpha" : "5",
"showBorder" : "0",
"showColumnShadow" : "0",
"labelDisplay" : 'Normal',
/* "slantLabels" : '0',*/
"canvasbgColor" : "#ff6418",
"legendNumColumns" : "13",
"legendItemFontSize":"8",
"showTrendlinesOnTop ":"0",
"interactiveLegend":"1",
"theme":"fint",
"animation":"0",
"numberSuffix": " %",
"yAxisMinValue":"0.00",
"yAxisMaxValue":"100.00",
"minimizetendency": "1",
"numDivLines":"5",
"showShadow": "0",
"showCanvasBorder": "0",
"chartBottomMargin":"0",
"usePlotGradientColor": "0",
/*"labelDisplay": "rotate",*/
"divlineThickness": "0",
"divLineDashed": "0",
"slantLabels": "0",
"divLineDashLen": "0",
"rotateValues" :"1",
"showToolTip" : "1",
"showAxisLines": "0"},
"styles": {
"definition": [
{
"name": "myToolTipFont",
"type": "font",
"size": "12"
}
],
"application": [
{
"toobject": "ToolTip",
"styles": "myToolTipFont"
}
]
},
"categories": [
{
"category": [
{
"label": "J",
"fontSize" : "6"
},
{
"label": "F",
"fontSize" : "6"
},
{
"label": "M",
"fontSize" : "6"
},
{
"label": "A",
"fontSize" : "6"
},
{
"label": "M",
"fontSize" : "6"
},
{
"vLine": "true",
"fontSize" : "6"
},
{
"label": "J",
"fontSize" : "6"
},
{
"label": "J",
"fontSize" : "6"
},
{
"label": "A",
"fontSize" : "6"
},
{
"label": "S",
"fontSize" : "6"
},
{
"label": "O",
"fontSize" : "6"
},
{
"label": "N",
"fontSize" : "6"
},
{
"label": "D",
"fontSize" : "6"
},
{
"label": "J",
"fontSize" : "6"
}
]
}
],
"dataset": [
{
"color": "#FF0000",
"seriesname": "Value ",
"data": [
{
"value": "44"
},
{
"value": "48"
},
{
"value": "54"
},
{
"value": "64"
},
{
"value": "55"
},
{
"value": "51"
},
{
"value": "60"
},
{
"value": "70"
},
{
"value": "78"
},
{
"value": "80"
},
{
"value": "81"
},
{
"value": "82"
},
{
"value": "85"
}
]
}
],
"trendlines": [
{
"line": [
{
"startvalue": "80",
"endValue" : "85",
"dashed" : "1"
},
{
"startvalue": "48",
"endValue" : "70",
"dashed" : "1"
}
]
}
]
}
});
chartContainerFive.render();
}
}//window render chart
The Trendlines feature cannot be used to fulfill your requirement of displaying two separate parts of trendline.
Alternatively, you could use the Line Annotation of FusionCharts to have a similar implementation as you require. For reference : http://www.fusioncharts.com/dev/advanced-chart-configurations/annotations/creating-annotations/creating-shape-annotations.html#line
To set the position of the line annotation, you could use the dynamic positioning Macros. For reference : http://www.fusioncharts.com/dev/advanced-chart-configurations/annotations/positioning-annotations-using-macros.html#positioning-annotations-with-respect-to-the-axes
Find a sample fiddle with similar implementation as you require : http://jsfiddle.net/Akash008/LE3Fa/154/
FusionCharts.ready(function () {
var chartContainerFive = new FusionCharts(
{
"id": "scoreCardContainerBarId",
"renderAt" : "chart-container",
"type": 'msline',
"width" : "100%",
"height" : "300",
"dataFormat": 'json',
"dataSource" : {
"chart": {"caption": "Enter the Caption here",
"captionFontSize" : "12",
"captionFontColor" : "#8a807c",
"captionFontBold" : "1",
"showLegend" : "0",
"bgcolor" : "FFFFFF",
"drawAnchors":"0",
"showalternatehgridcolor" : "1",
"showValues" : "0",
"canvasborderalpha" : "0",
//"legendposition" : "right",
"legendshadow" : "0",
"legendborderalpha" : "0",
"palettecolors" : "#f8bd19,#008ee4,#33bdda,#e44a00,#6baa01,#583e78",
"exportEnabled" : "0",
"exportFileName" : "QCDDMSESChange",
"showToolTipShadow" : "1",
"toolTipBorderRadius" : "6",
"canvasbgAlpha" : "5",
"showBorder" : "0",
"showColumnShadow" : "0",
"labelDisplay" : 'Normal',
/* "slantLabels" : '0',*/
"canvasbgColor" : "#ff6418",
"legendNumColumns" : "13",
"legendItemFontSize":"8",
"showTrendlinesOnTop ":"0",
"interactiveLegend":"1",
"theme":"fint",
"animation":"0",
"numberSuffix": " %",
"yAxisMinValue":"0.00",
"yAxisMaxValue":"100.00",
"minimizetendency": "1",
"numDivLines":"5",
"showShadow": "0",
"showCanvasBorder": "0",
"chartBottomMargin":"0",
"usePlotGradientColor": "0",
/*"labelDisplay": "rotate",*/
"divlineThickness": "0",
"divLineDashed": "0",
"slantLabels": "0",
"divLineDashLen": "0",
"rotateValues" :"1",
"showToolTip" : "1",
"showAxisLines": "0"},
"styles": {
"definition": [
{
"name": "myToolTipFont",
"type": "font",
"size": "12"
}
],
"application": [
{
"toobject": "ToolTip",
"styles": "myToolTipFont"
}
]
},
"categories": [
{
"category": [
{
"label": "J",
"fontSize" : "6"
},
{
"label": "F",
"fontSize" : "6"
},
{
"label": "M",
"fontSize" : "6"
},
{
"label": "A",
"fontSize" : "6"
},
{
"label": "M",
"fontSize" : "6"
},
{
"vLine": "true",
"fontSize" : "6"
},
{
"label": "J",
"fontSize" : "6"
},
{
"label": "J",
"fontSize" : "6"
},
{
"label": "A",
"fontSize" : "6"
},
{
"label": "S",
"fontSize" : "6"
},
{
"label": "O",
"fontSize" : "6"
},
{
"label": "N",
"fontSize" : "6"
},
{
"label": "D",
"fontSize" : "6"
},
{
"label": "J",
"fontSize" : "6"
}
]
}
],
"dataset": [
{
"color": "#FF0000",
"seriesname": "Value ",
"data": [
{
"value": "44"
},
{
"value": "48"
},
{
"value": "54"
},
{
"value": "64"
},
{
"value": "55"
},
{
"value": "51"
},
{
"value": "60"
},
{
"value": "70"
},
{
"value": "78"
},
{
"value": "80"
},
{
"value": "81"
},
{
"value": "82"
},
{
"value": "85"
}
]
}
],
/*"trendlines": [
{
"line": [
{
"startvalue": "80",
"endValue" : "85",
"dashed" : "1"
},
{
"startvalue": "48",
"endValue" : "70",
"dashed" : "1"
}
]
}
],*/
"annotations": {
"showBelow" : "0",
"width": "500",
"height": "100",
"autoScale": "1",
"groups": [
{
"id": "user-images",
"items": [
{
"id": "line-part-1",
"type": "line",
"color": "#00FF00",
"x": "$xaxis.label.0.x",
"y": "$yaxis.label.2.y",
"toX": "$xaxis.label.4.x+22",
"toY": "$yaxis.label.2.y"
},
{
"id": "line-part-2",
"type": "line",
"color": "##0000FF",
"x": "$xaxis.label.4.x+22",
"y": "$yaxis.label.3.y",
"toX": "$xaxis.label.12.x+4",
"toY": "$yaxis.label.3.y"
}
]
}
]
}
}
});
chartContainerFive.render();
});

Extracting variable number of fields using jq

I am new to this website and came here because I am really struggling with a problem of extracting information from a JSON file. The tricky part is that there are variable number of fields, so I can't get away with simple syntax.
Here's a sample code:
{
"addresses": {
"#count": "1",
"address_name": {
"address_spec": {
"#addr_no": "1",
"full_address": "Tel Aviv Univ, Eitan Berglas Sch Econ, IL-69978 Tel Aviv, Israel",
"organizations": {
"#count": "2",
"organization": [
"Tel Aviv Univ",
{
"#pref": "Y",
"#text": "Tel Aviv University"
}
]
},
"suborganizations": {
"#count": "1",
"suborganization": "Eitan Berglas Sch Econ"
},
"city": "Tel Aviv",
"country": "Israel",
"zip": {
"#location": "BC",
"#text": "IL-69978"
}
}
}
},
"category_info": {
"headings": {
"#count": "1",
"heading": "Social Sciences"
},
"subjects": {
"#count": "3",
"subject": [
{
"#ascatype": "traditional",
"#text": "Economics"
},
{
"#ascatype": "extended",
"#text": "Business & Economics"
},
{
"#ascatype": "traditional",
"#text": "ECONOMICS"
}
]
}
}
}
{
"addresses": {
"#count": "1",
"address_name": {
"address_spec": {
"#addr_no": "1",
"full_address": "MIT, Cambridge, MA 02139 USA",
"organizations": {
"#count": "2",
"organization": [
"MIT",
{
"#pref": "Y",
"#text": "Massachusetts Institute of Technology (MIT)"
}
]
},
"city": "Cambridge",
"state": "MA",
"country": "USA",
"zip": {
"#location": "AP",
"#text": "02139"
}
}
}
},
"category_info": {
"headings": {
"#count": "1",
"heading": "Social Sciences"
},
"subjects": {
"#count": "3",
"subject": [
{
"#ascatype": "traditional",
"#text": "Economics"
},
{
"#ascatype": "extended",
"#text": "Business & Economics"
},
{
"#ascatype": "traditional",
"#text": "ECONOMICS"
}
]
}
}
}
{
"addresses": {
"#count": "2",
"address_name": [
{
"address_spec": {
"#addr_no": "1",
"full_address": "Univ Kentucky, Lexington, KY 40506 USA",
"organizations": {
"#count": "2",
"organization": [
"Univ Kentucky",
{
"#pref": "Y",
"#text": "University of Kentucky"
}
]
},
"city": "Lexington",
"state": "KY",
"country": "USA",
"zip": {
"#location": "AP",
"#text": "40506"
}
}
},
{
"address_spec": {
"#addr_no": "2",
"full_address": "Univ Bonn, ZEI, D-5300 Bonn, Germany",
"organizations": {
"#count": "2",
"organization": [
"Univ Bonn",
{
"#pref": "Y",
"#text": "University of Bonn"
}
]
},
"suborganizations": {
"#count": "1",
"suborganization": "ZEI"
},
"city": "Bonn",
"country": "Germany",
"zip": {
"#location": "BC",
"#text": "D-5300"
}
}
}
]
},
"category_info": {
"headings": {
"#count": "1",
"heading": "Social Sciences"
},
"subjects": {
"#count": "3",
"subject": [
{
"#ascatype": "traditional",
"#text": "Economics"
},
{
"#ascatype": "extended",
"#text": "Business & Economics"
},
{
"#ascatype": "traditional",
"#text": "ECONOMICS"
}
]
}
}
}
{
"addresses": {
"#count": "1",
"address_name": {
"address_spec": {
"#addr_no": "1",
"full_address": "Harvard Univ, Cambridge, MA 02138 USA",
"organizations": {
"#count": "2",
"organization": [
"Harvard Univ",
{
"#pref": "Y",
"#text": "Harvard University"
}
]
},
"city": "Cambridge",
"state": "MA",
"country": "USA",
"zip": {
"#location": "AP",
"#text": "02138"
}
}
}
},
"category_info": {
"headings": {
"#count": "1",
"heading": "Social Sciences"
},
"subjects": {
"#count": "3",
"subject": [
{
"#ascatype": "traditional",
"#text": "Economics"
},
{
"#ascatype": "extended",
"#text": "Business & Economics"
},
{
"#ascatype": "traditional",
"#text": "ECONOMICS"
}
]
}
}
}
{
"addresses": {
"#count": "3",
"address_name": [
{
"address_spec": {
"#addr_no": "1",
"full_address": "Columbia Univ, New York, NY 10027 USA",
"organizations": {
"#count": "2",
"organization": [
"Columbia Univ",
{
"#pref": "Y",
"#text": "Columbia University"
}
]
},
"city": "New York",
"state": "NY",
"country": "USA",
"zip": {
"#location": "AP",
"#text": "10027"
}
}
},
{
"address_spec": {
"#addr_no": "2",
"full_address": "NYU, New York, NY USA",
"organizations": {
"#count": "2",
"organization": [
"NYU",
{
"#pref": "Y",
"#text": "New York University"
}
]
},
"city": "New York",
"state": "NY",
"country": "USA"
}
},
{
"address_spec": {
"#addr_no": "3",
"full_address": "Univ Pompeu Fabra, Barcelona, Spain",
"organizations": {
"#count": "2",
"organization": [
"Univ Pompeu Fabra",
{
"#pref": "Y",
"#text": "Pompeu Fabra University"
}
]
},
"city": "Barcelona",
"country": "Spain"
}
}
]
},
"category_info": {
"headings": {
"#count": "1",
"heading": "Social Sciences"
},
"subjects": {
"#count": "3",
"subject": [
{
"#ascatype": "traditional",
"#text": "Economics"
},
{
"#ascatype": "extended",
"#text": "Business & Economics"
},
{
"#ascatype": "traditional",
"#text": "ECONOMICS"
}
]
}
}
}
{
"addresses": {
"#count": "2",
"address_name": [
{
"address_spec": {
"#addr_no": "1",
"full_address": "Univ Chicago, Chicago, IL 60637 USA",
"organizations": {
"#count": "2",
"organization": [
"Univ Chicago",
{
"#pref": "Y",
"#text": "University of Chicago"
}
]
},
"city": "Chicago",
"state": "IL",
"country": "USA",
"zip": {
"#location": "AP",
"#text": "60637"
}
}
},
{
"address_spec": {
"#addr_no": "2",
"full_address": "Amer Bar Fdn, Chicago, IL 60611 USA",
"organizations": {
"#count": "1",
"organization": "Amer Bar Fdn"
},
"city": "Chicago",
"state": "IL",
"country": "USA",
"zip": {
"#location": "AP",
"#text": "60611"
}
}
}
]
},
"category_info": {
"headings": {
"#count": "1",
"heading": "Social Sciences"
},
"subjects": {
"#count": "3",
"subject": [
{
"#ascatype": "traditional",
"#text": "Economics"
},
{
"#ascatype": "extended",
"#text": "Business & Economics"
},
{
"#ascatype": "traditional",
"#text": "ECONOMICS"
}
]
}
}
}
{
"addresses": {
"#count": "2",
"address_name": [
{
"address_spec": {
"#addr_no": "1",
"full_address": "Ohio State Univ, Columbus, OH 43210 USA",
"organizations": {
"#count": "2",
"organization": [
"Ohio State Univ",
{
"#pref": "Y",
"#text": "Ohio State University"
}
]
},
"city": "Columbus",
"state": "OH",
"country": "USA",
"zip": {
"#location": "AP",
"#text": "43210"
}
}
},
{
"address_spec": {
"#addr_no": "2",
"full_address": "Harvard Univ, Cambridge, MA 02138 USA",
"organizations": {
"#count": "2",
"organization": [
"Harvard Univ",
{
"#pref": "Y",
"#text": "Harvard University"
}
]
},
"city": "Cambridge",
"state": "MA",
"country": "USA",
"zip": {
"#location": "AP",
"#text": "02138"
}
}
}
]
},
"category_info": {
"headings": {
"#count": "1",
"heading": "Social Sciences"
},
"subjects": {
"#count": "3",
"subject": [
{
"#ascatype": "traditional",
"#text": "Economics"
},
{
"#ascatype": "extended",
"#text": "Business & Economics"
},
{
"#ascatype": "traditional",
"#text": "ECONOMICS"
}
]
}
}
}
{
"addresses": {
"#count": "1",
"address_name": {
"address_spec": {
"#addr_no": "1",
"full_address": "Univ Chicago, Chicago, IL 60637 USA",
"organizations": {
"#count": "2",
"organization": [
"Univ Chicago",
{
"#pref": "Y",
"#text": "University of Chicago"
}
]
},
"city": "Chicago",
"state": "IL",
"country": "USA",
"zip": {
"#location": "AP",
"#text": "60637"
}
}
}
},
"category_info": {
"headings": {
"#count": "1",
"heading": "Social Sciences"
},
"subjects": {
"#count": "3",
"subject": [
{
"#ascatype": "traditional",
"#text": "Economics"
},
{
"#ascatype": "extended",
"#text": "Business & Economics"
},
{
"#ascatype": "traditional",
"#text": "ECONOMICS"
}
]
}
}
}
{
"addresses": {
"#count": "2",
"address_name": [
{
"address_spec": {
"#addr_no": "1",
"full_address": "Wissensch Zentrum Berlin Sozialforsch, D-1000 Berlin, Germany",
"organizations": {
"#count": "1",
"organization": "Wissensch Zentrum Berlin Sozialforsch"
},
"city": "Berlin",
"country": "Germany",
"zip": {
"#location": "BC",
"#text": "D-1000"
}
}
},
{
"address_spec": {
"#addr_no": "2",
"full_address": "Harvard Univ, Dept Govt, Cambridge, MA 02138 USA",
"organizations": {
"#count": "2",
"organization": [
"Harvard Univ",
{
"#pref": "Y",
"#text": "Harvard University"
}
]
},
"suborganizations": {
"#count": "1",
"suborganization": "Dept Govt"
},
"city": "Cambridge",
"state": "MA",
"country": "USA",
"zip": {
"#location": "AP",
"#text": "02138"
}
}
}
]
},
"category_info": {
"headings": {
"#count": "1",
"heading": "Social Sciences"
},
"subjects": {
"#count": "3",
"subject": [
{
"#ascatype": "traditional",
"#text": "Economics"
},
{
"#ascatype": "extended",
"#text": "Business & Economics"
},
{
"#ascatype": "traditional",
"#text": "ECONOMICS"
}
]
}
}
}
{
"addresses": {
"#count": "2",
"address_name": [
{
"address_spec": {
"#addr_no": "1",
"full_address": "NYU, CV Starr Ctr Appl Econ, New York, NY 10003 USA",
"organizations": {
"#count": "2",
"organization": [
"NYU",
{
"#pref": "Y",
"#text": "New York University"
}
]
},
"suborganizations": {
"#count": "1",
"suborganization": "CV Starr Ctr Appl Econ"
},
"city": "New York",
"state": "NY",
"country": "USA",
"zip": {
"#location": "AP",
"#text": "10003"
}
}
},
{
"address_spec": {
"#addr_no": "2",
"full_address": "Princeton Univ, Princeton, NJ 08544 USA",
"organizations": {
"#count": "2",
"organization": [
"Princeton Univ",
{
"#pref": "Y",
"#text": "Princeton University"
}
]
},
"city": "Princeton",
"state": "NJ",
"country": "USA",
"zip": {
"#location": "AP",
"#text": "08544"
}
}
}
]
},
"category_info": {
"headings": {
"#count": "1",
"heading": "Social Sciences"
},
"subjects": {
"#count": "3",
"subject": [
{
"#ascatype": "traditional",
"#text": "Economics"
},
{
"#ascatype": "extended",
"#text": "Business & Economics"
},
{
"#ascatype": "traditional",
"#text": "ECONOMICS"
}
]
}
}
}
What I was hoping to extract is a country for each of the records (some records have more than one country, which seems to be causing the problem). So my naive approach was to say:
.static_data."fullrecord_metadata".addresses.address_name.country
This however gives me several errors (null has no keys, and cannot index array with string). Checking using the keys command:
.static_data."fullrecord_metadata".addresses.address_name | keys
I can see that it's seems there's a problem with the way the data is structured...
So, could you suggest if I can actually extract the list of countries for each entry using jq? Thank you!
For each input top-level JSON entity, the following filter will recursively examine all the objects to see if they have a "country" key, and it will then report the distinct "country" values for that top-level entity:
jq -c '[.. | if type == "object" and has("country")
then .country
else empty end] | unique'
["Israel"]
["USA"]
["Germany","USA"]
["USA"]
["Spain","USA"]
["USA"]
["USA"]
["USA"]
["Germany","USA"]
["USA"]
Here's a filter that will produce the same results in your example, though it is not exactly equivalent:
[.. | .country? // empty] | unique
[Exercise for the interested reader: what is the difference? :-) ]
Here is a solution which uses a function to handle the variation in .address_name
def address_specs:
if type == "array" then .[].address_spec else .address_spec end
;
.addresses | .address_name | [address_specs | .country] | unique

JSON string into Object Model using Newtonsoft library

I have the following JSON string :
{
"screen": {
"#id": "12345",
"#name": "My Screening Questionnaire",
"#successful": "True",
"question": [
{
"#id": "123",
"#type": "MultipleChoiceOneAnswer",
"#text": "What is your current work status?",
"answer": [
{
"#id": "1",
"#selected": "True",
"#text": "Australian citizen"
},
{
"#id": "2",
"#text": "NZ citizen"
},
{
"#id": "3",
"#text": "Australian permanent resident"
},
{
"#id": "4",
"#text": "NZ permanent resident"
},
{
"#id": "5",
"#text": "Australian work visa"
},
{
"#id": "6",
"#text": "NZ work visa"
},
{
"#id": "7",
"#text": "Holiday working visa"
},
{
"#id": "8",
"#text": "Other"
}
]
},
{
"#id": "124",
"#type": "MultipleChoiceOneAnswer",
"#text": "When are you available to begin employment?",
"answer": [
{
"#id": "1",
"#selected": "True",
"#text": "Now"
},
{
"#id": "2",
"#text": "2 weeks"
},
{
"#id": "3",
"#text": "1 month"
},
{
"#id": "4",
"#text": "1 –2 months"
},
{
"#id": "5",
"#text": "3 or more months"
}
]
},
{
"#id": "125",
"#type": "Text",
"#text": "Why do you consider yourself to be a suitable candidate for this position?",
"answer": {
"#id": "1",
"#selected": "True",
"#text": "I’m great"
}
}
]
}
}
I want to convert it into an Object model using Newtonsoft
JsonConvert.DeserializeObject:T:(JsonStringText)
What will be the structure of the object Model ?
Thanks.
You can refer to the JSON model returned here :
http://developer.seek.com.au/docs/partner-api/api-methods/applicationexport/get-screen