python: retrieve a section of JSON data, without knowing the structure -


i have json:

 {u'spreadsheetid': u'19cugmhb1ds6n1jby4zo4hk_k4sqstmoffccxrc2qo',      u'properties': {u'locale': u'en_us', u'timezone': u'asia/hong_kong',     u'autorecalc': u'on_change', u'defaultformat': {u'padding': {u'top': 2, u'right': 3, u'left': 3, u'bottom': 2}, u'textformat': {u'foregroundcolor': {}, u'bold': false, u'strikethrough': false, u'fontfamily': u'arial,sans,sans-serif', u'fontsize': 10, u'italic': false, u'underline': false}, u'verticalalignment': u'bottom', u'backgroundcolor': {u'blue': 1, u'green': 1, u'red': 1}, u'wrapstrategy': u'overflow_cell'}, u'title': u'test pygsheets api v4'}, u'sheets': [{u'properties': {u'sheettype': u'grid', u'index': 0, u'sheetid': 0, u'gridproperties': {u'columncount': 26, u'rowcount': 1000}, u'title': u'io'}}, {u'basicfilter': {u'range': {u'endrowindex': 978, u'startrowindex': 2, u'sheetid': 1704577069, u'startcolumnindex': 1, u'endcolumnindex': 9}, u'sortspecs': [{u'sortorder': u'ascending', u'dimensionindex': 1}, {u'sortorder': u'ascending', u'dimensionindex': 4}, {u'sortorder': u'ascending', u'dimensionindex': 5}, {u'sortorder': u'ascending', u'dimensionindex': 8}, {u'sortorder': u'ascending', u'dimensionindex': 3}, {u'sortorder': u'ascending', u'dimensionindex': 7}, {u'sortorder': u'ascending', u'dimensionindex': 2}]}, u'properties': {u'sheettype': u'grid', u'index': 1, u'title': u'books', u'gridproperties': {u'columncount': 22, u'rowcount': 978, u'frozencolumncount': 3, u'hidegridlines': true, u'frozenrowcount': 3}, u'tabcolor': {u'blue': 1}, u'sheetid': 1704577069}}], u'spreadsheeturl': u'https://docs.google.com/spreadsheets/d/1cugmhb1ds6n1jby4zo4hk_k4sqstmoffccxrc2qo/edit'} 

how titles out of json sheets only? want

input: results.get('title')

output: ['io','books']

i'm not sure how approach because of nested structure. reminds of html node type structure. need type of search function?

is there way title nodes without looking @ structure? kind of xpath search type function? have used beautifulsoup before, , can not know structure , take out parts of data through search.

this give desired output:

print [x['properties'].get('title') x in results['sheets']] 

this returns: [u'io', u'books']


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -