#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2014
    Posts
    3
    Rep Power
    0

    Help in reading a joson file and print some data


    Hi, I am new to python programming, I would like to print sequenceid, keyid, and contents under "Reportavailability" node from each record. Any help appreciated.Thanks

    Script:

    import json
    from pprint import pprint

    with open('Companies25.json') as data_file:
    data = json.load(data_file)

    # print data

    both = []

    for datum in data:
    both.append((datum[u"SequenceID"], datum[u'Data'][u'KeyID']))

    #both.sort()
    pprint(both)



    Getting these eroors:

    Traceback (most recent call last):
    File "C:\Python27\Seqid_keyid_test.py", line 5, in <module>
    data = json.load(data_file)
    File "C:\Python27\lib\json\__init__.py", line 290, in load
    **kw)
    File "C:\Python27\lib\json\__init__.py", line 338, in loads
    return _default_decoder.decode(s)
    File "C:\Python27\lib\json\decoder.py", line 365, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
    File "C:\Python27\lib\json\decoder.py", line 381, in raw_decode
    obj, end = self.scan_once(s, idx)
    UnicodeDecodeError: 'utf8' codec can't decode byte 0x92 in position 130: invalid
    start byte


    1 sample record from "Companies25.json" file contents listed below:

    [
    {
    "SequenceID": "1",
    "ObjectType": "2",
    "Data": {
    "KeyID": "381",
    "AbiNumber": "115523672",
    "Address1": "One AAR Place, 1100 North Wood Dale Road",
    "AreaCode": "630 ",
    "Assets": "2.1368999e+003",
    "AssetsEUR": "1.6379733e+003",
    "AssetsGBP": "1.4051989e+003",
    "AssetsUSD": "2.1368999e+003",
    "Auditor": "KPMG LLP",
    "City": "Wood Dale",
    "CompanyLogo": "1",
    "CompanyName": "AAR Corp.",
    "ComponentID": "1",
    "CompanyTypeID": "516",
    "CountryID": "42026046",
    "CountyID": "12546",
    "CreditAlphaScore": "A+",
    "CreditLimit": "500000",
    "CreditLimitCurrency": "USD",
    "CreditNumericScore": "100",
    "CurrencyISO3": "USD",
    "DayFounded": "11",
    "Dormant": "0",
    "Employees": "6300",
    "EntityTypeID": "4",
    "ExecutiveCount": "169",
    "Fax": "630-227-2039",
    "Fortune1000Ranking": "929",
    "Fortune1000RankingFlag": "1",
    "GazetteCode": "0",
    "HighTechnologyProductCodes": "ZZZ-HC",
    "IndustryGroupID": "220502",
    "Inherited": "0",
    "Latitude": "41.986616",
    "Longitude": "-87.979914",
    "MarketValue": "1.0929709e+003",
    "MarketValueCurrency": "USD",
    "MarketValueDate": "2014-01-17",
    "MarketValueEUR": "8.0370239e+002",
    "MarketValueGBP": "6.6903210e+002",
    "MarketValueUSD": "1.0929709e+003",
    "MonthFounded": "4",
    "MSACode": "16980",
    "OperatingProfit": "1.2230000e+002",
    "OperatingProfitEUR": "9.4960892e+001",
    "OperatingProfitGBP": "7.7920891e+001",
    "OperatingProfitUSD": "1.2230000e+002",
    "OS2010IndustryID": "8",
    "OwnershipTypeID": "2",
    "ParentKeyID": "381",
    "Phone": "630-227-2000",
    "PostalCode": "60191",
    "PostalCodePrefix": "601 ",
    "PreTaxProfit": "8.2199997e+001",
    "PreTaxProfitEUR": "6.3824894e+001",
    "PreTaxProfitGBP": "5.2372009e+001",
    "PreTaxProfitUSD": "8.2199997e+001",
    "PrimaryANZSIC": "2394",
    "PrimaryISICRev4": "3030",
    "PrimaryNACE": "3530",
    "PrimaryNACERev2": "3030",
    "PrimaryNAIC": "336411",
    "PrimaryNAICS2012": "336411",
    "PrimaryUK2007SIC": "3030",
    "PrimaryUKSIC": "3530",
    "PrimaryUSSIC": "3721",
    "PublicOrTopUK": "1",
    "PublicUS": "1",
    "QuotedStatus": "1",
    "Sales": "2.1373000e+003",
    "Sales1YearGrowth": "3.5013001e+000",
    "SalesEUR": "1.6595250e+003",
    "SalesGBP": "1.3617361e+003",
    "SalesUSD": "2.1373000e+003",
    "SEDOL": "2001119",
    "SmLinkedInCompanyID": "207350",
    "SquareFootageID": "4",
    "StateOrProvinceID": "46490503",
    "StockExchangeID": "47",
    "TickerExchange": "New York Stock Exchange",
    "TickerSymbol": "AIR",
    "TollFreePhone": "(800) 422-2213",
    "TopUK": "0",
    "TotalCorpFamMembers": "59",
    "TotalLiabilities": "1.2183000e+003",
    "TotalLiabilitiesEUR": "9.3384949e+002",
    "TotalLiabilitiesGBP": "8.0113898e+002",
    "TotalLiabilitiesUSD": "1.2183000e+003",
    "TPSflag": "0",
    "UltimateParentKeyID": "381",
    "VendorFeedID": "20",
    "VendorFeedID_CreditLimit": "40",
    "VendorFeedID_CreditScore": "40",
    "VendorFeedID_GeoLocation": "40",
    "VendorFeedID_TollFreePhone": "70",
    "YearFounded": "1966",
    "ReportAvailability":
    {
    "company_directors": "1",
    "company_jobs": "1",
    "company_corporate_family": "1",
    "company_industry_snapshot": "1",
    "company_industry_snapshot_pdf": "1",
    "company_swot": "0",
    "company_credit_us": "1",
    "company_credit_uk": "0",
    "company_strategic": "0",
    "company_analyst_reports": "1",
    "company_valuation_tearsheet": "1",
    "company_chartbook": "1",
    "company_ratios": "1",
    "company_annual": "1",
    "company_financial_health": "1",
    "company_ratio_comparison": "1",
    "company_stock": "1",
    "company_geo_segment": "1",
    "company_income": "1",
    "company_income_as_reported": "1",
    "company_interim_income": "1",
    "company_interim_income_as_reported": "1",
    "company_balance_sheet": "1",
    "company_balance_sheet_as_reported": "1",
    "company_interim_balance_sheet": "1",
    "company_interim_balance_sheet_as_reported": "1",
    "company_cash_flow": "1",
    "company_cash_flow_as_reported": "1",
    "company_interim_cash_flow": "1",
    "company_interim_cash_flow_as_reported": "1"
    },
    "SignalTrigBankruptcy": "N",
    "SignalTrigBankruptcyIPCV": "0",
    "SignalTrigConferenceActivity": "Y",
    "SignalTrigConferenceActivityIPCV": "0.694406",
    "SignalTrigContractWin": "Y",
    "SignalTrigContractWinIPCV": "0.984184",
    "SignalTrigDivesting": "N",
    "SignalTrigDivestingIPCV": "0",
    "SignalTrigExecChangeAll": "N",
    "SignalTrigExecChangeAllIPCV": "0",
    "SignalTrigExecChangeBOD": "N",
    "SignalTrigExecChangeBODIPCV": "0",
    "SignalTrigExecChangeCompanyOversight": "N",
    "SignalTrigExecChangeCompanyOversightIPCV": "0",
    "SignalTrigExecChangeEngineering": "N",
    "SignalTrigExecChangeEngineeringIPCV": "0",
    "SignalTrigExecChangeFinance": "N",
    "SignalTrigExecChangeFinanceIPCV": "0",
    "SignalTrigExecChangeIT": "N",
    "SignalTrigExecChangeITIPCV": "0",
    "SignalTrigExecChangeLegal": "N",
    "SignalTrigExecChangeLegalIPCV": "0",
    "SignalTrigExecChangePR": "N",
    "SignalTrigExecChangePRIPCV": "0",
    "SignalTrigExecChangeSalesMKTG": "N",
    "SignalTrigExecChangeSalesMKTGIPCV": "0",
    "SignalTrigFDAApproval": "N",
    "SignalTrigFDAApprovalIPCV": "0",
    "SignalTrigIPOActivity": "N",
    "SignalTrigIPOActivityIPCV": "0",
    "SignalTrigLaunchingProduct": "Y",
    "SignalTrigLaunchingProductIPCV": "0.41186",
    "SignalTrigLayoffActivity": "Y",
    "SignalTrigLayoffActivityIPCV": "0.380786",
    "SignalTrigLegalIssues": "N",
    "SignalTrigLegalIssuesIPCV": "0",
    "SignalTrigMandA": "Y",
    "SignalTrigMandAIPCV": "0.622442",
    "SignalTrigNewFacilityOpening": "Y",
    "SignalTrigNewFacilityOpeningIPCV": "0.0778683",
    "SignalTrigPartnership": "Y",
    "SignalTrigPartnershipIPCV": "0.809397",
    "SignalTrigRelocation": "N",
    "SignalTrigRelocationIPCV": "0",
    "SignalTrigVentureFinancing": "Y",
    "SignalTrigVentureFinancingIPCV": "0.480756",
    "SignalTrigAssetIncrease": "N",
    "SignalTrigAssetIncreaseIPCV": "0",
    "SignalTrigAssetDecrease": "N",
    "SignalTrigAssetDecreaseIPCV": "0",
    "SignalTrigEmployeeIncrease": "N",
    "SignalTrigEmployeeIncreaseIPCV": "0",
    "SignalTrigEmployeeDecrease": "N",
    "SignalTrigEmployeeDecreaseIPCV": "0",
    "SignalTrigLiabilitiesIncrease": "N",
    "SignalTrigLiabilitiesIncreaseIPCV": "0",
    "SignalTrigLiabilitiesDecrease": "N",
    "SignalTrigLiabilitiesDecreaseIPCV": "0",
    "SignalTrigProfitIncrease": "N",
    "SignalTrigProfitIncreaseIPCV": "0",
    "SignalTrigProfitDecrease": "N",
    "SignalTrigProfitDecreaseIPCV": "0",
    "SignalTrigRevenueIncrease": "N",
    "SignalTrigRevenueIncreaseIPCV": "0",
    "SignalTrigRevenueDecrease": "N",
    "SignalTrigRevenueDecreaseIPCV": "0",
    "SignalFinTradesPublic": "ON",
    "SignalFinTradesPublicIPCV": "1",
    "SignalTradesOnAmman": "N",
    "SignalTradesOnAmmanIPCV": "0",
    "SignalTradesOnAthensStockExchange": "N",
    "SignalTradesOnAthensStockExchangeIPCV": "0",
    "SignalTradesOnAustralianStockExchange": "N",
    "SignalTradesOnAustralianStockExchangeIPCV": "0",
    "SignalTradesOnBangkokStockExchange": "N",
    "SignalTradesOnBangkokStockExchangeIPCV": "0",
    "SignalTradesOnBombayStockExchange": "N",
    "SignalTradesOnBombayStockExchangeIPCV": "0",
    "SignalTradesOnBorsaItaliana": "N",
    "SignalTradesOnBorsaItalianaIPCV": "0",
    "SignalTradesOnBudapestStockExchange": "N",
    "SignalTradesOnBudapestStockExchangeIPCV": "0",
    "SignalTradesOnBuenosAiresStockExchange": "N",
    "SignalTradesOnBuenosAiresStockExchangeIPCV": "0",
    "SignalTradesOnBulgarianStockExchange": "N",
    "SignalTradesOnBulgarianStockExchangeIPCV": "0",
    "SignalTradesOnCairoAndAlexandriaStockExchange": "N",
    "SignalTradesOnCairoAndAlexandriaStockExchangeIPCV": "0",
    "SignalTradesOnCaracasStockExchange": "N",
    "SignalTradesOnCaracasStockExchangeIPCV": "0",
    "SignalTradesOnCaribbean": "N",
    "SignalTradesOnCaribbeanIPCV": "0",
    "SignalTradesOnCasablancaStockExchange": "N",
    "SignalTradesOnCasablancaStockExchangeIPCV": "0",
    "SignalTradesOnColombiaStockExchange": "N",
    "SignalTradesOnColombiaStockExchangeIPCV": "0",
    "SignalTradesOnColomboStockExchange": "N",
    "SignalTradesOnColomboStockExchangeIPCV": "0",
    "SignalTradesOnCopenhagenStockExchange": "N",
    "SignalTradesOnCopenhagenStockExchangeIPCV": "0",
    "SignalTradesOnEuronextAmsterdam": "N",
    "SignalTradesOnEuronextAmsterdamIPCV": "0",
    "SignalTradesOnEuronextBrussels": "N",
    "SignalTradesOnEuronextBrusselsIPCV": "0",
    "SignalTradesOnEuronextParis": "N",
    "SignalTradesOnEuronextParisIPCV": "0",
    "SignalTradesOnFrankfurtStockExchange": "N",
    "SignalTradesOnFrankfurtStockExchangeIPCV": "0",
    "SignalTradesOnHelsinkiStockExchange": "N",
    "SignalTradesOnHelsinkiStockExchangeIPCV": "0",
    "SignalTradesOnHongKongStockExchange": "N",
    "SignalTradesOnHongKongStockExchangeIPCV": "0",
    "SignalTradesOnIrishStockExchange": "N",
    "SignalTradesOnIrishStockExchangeIPCV": "0",
    "SignalTradesOnIstanbulStockExchange": "N",
    "SignalTradesOnIstanbulStockExchangeIPCV": "0",
    "SignalTradesOnJASDAQ": "N",
    "SignalTradesOnJASDAQIPCV": "0",
    "SignalTradesOnJohannesburgStockExchange": "N",
    "SignalTradesOnJohannesburgStockExchangeIPCV": "0",
    "SignalTradesOnKarachiStockExchange": "N",
    "SignalTradesOnKarachiStockExchangeIPCV": "0",
    "SignalTradesOnKazakhstanStockExchange": "N",
    "SignalTradesOnKazakhstanStockExchangeIPCV": "0",
    "SignalTradesOnKoreanStockExchange": "N",
    "SignalTradesOnKoreanStockExchangeIPCV": "0",
    "SignalTradesOnKOSDAQ": "N",
    "SignalTradesOnKOSDAQIPCV": "0",
    "SignalTradesOnKualaLumpurStockExchange": "N",
    "SignalTradesOnKualaLumpurStockExchangeIPCV": "0",
    "SignalTradesOnLimaStockExchange": "N",
    "SignalTradesOnLimaStockExchangeIPCV": "0",
    "SignalTradesOnLjubljanaStockExchange": "N",
    "SignalTradesOnLjubljanaStockExchangeIPCV": "0",
    "SignalTradesOnLondonAIM": "N",
    "SignalTradesOnLondonAIMIPCV": "0",
    "SignalTradesOnLondonStockExchange": "N",
    "SignalTradesOnLondonStockExchangeIPCV": "0",
    "SignalTradesOnLuxembourgStockExchange": "N",
    "SignalTradesOnLuxembourgStockExchangeIPCV": "0",
    "SignalTradesOnMadridStockExchange": "N",
    "SignalTradesOnMadridStockExchangeIPCV": "0",
    "SignalTradesOnMauritius": "N",
    "SignalTradesOnMauritiusIPCV": "0",
    "SignalTradesOnMexicanStockExchange": "N",
    "SignalTradesOnMexicanStockExchangeIPCV": "0",
    "SignalTradesOnNagoyaStockExchange": "N",
    "SignalTradesOnNagoyaStockExchangeIPCV": "0",
    "SignalTradesOnNairobiStockExchange": "N",
    "SignalTradesOnNairobiStockExchangeIPCV": "0",
    "SignalTradesOnNASDAQ": "N",
    "SignalTradesOnNASDAQIPCV": "0",
    "SignalTradesOnNationalStockExchangeofIndia": "N",
    "SignalTradesOnNationalStockExchangeofIndiaIPCV": "0",
    "SignalTradesOnNewZealandStockExchange": "N",
    "SignalTradesOnNewZealandStockExchangeIPCV": "0",
    "SignalTradesOnNYSE": "ON",
    "SignalTradesOnNYSEIPCV": "1",
    "SignalTradesOnOsloStockExchange": "N",
    "SignalTradesOnOsloStockExchangeIPCV": "0",
    "SignalTradesOnOTC": "N",
    "SignalTradesOnOTCIPCV": "0",
    "SignalTradesOnOther": "N",
    "SignalTradesOnOtherIPCV": "0",
    "SignalTradesOnPhilippineStockExchange": "N",
    "SignalTradesOnPhilippineStockExchangeIPCV": "0",
    "SignalTradesOnPragueStockExchange": "N",
    "SignalTradesOnPragueStockExchangeIPCV": "0",
    "SignalTradesOnRASDAQ": "N",
    "SignalTradesOnRASDAQIPCV": "0",
    "SignalTradesOnSecondMarche": "N",
    "SignalTradesOnSecondMarcheIPCV": "0",
    "SignalTradesOnShanghaiStockExchange": "N",
    "SignalTradesOnShanghaiStockExchangeIPCV": "0",
    "SignalTradesOnShenzhenStockExchange": "N",
    "SignalTradesOnShenzhenStockExchangeIPCV": "0",
    "SignalTradesOnSingaporeStockExchange": "N",
    "SignalTradesOnSingaporeStockExchangeIPCV": "0",
    "SignalTradesOnStockholmStockExchange": "N",
    "SignalTradesOnStockholmStockExchangeIPCV": "0",
    "SignalTradesOnSwissExchange": "N",
    "SignalTradesOnSwissExchangeIPCV": "0",
    "SignalTradesOnTaiwanStockExchange": "N",
    "SignalTradesOnTaiwanStockExchangeIPCV": "0",
    "SignalTradesOnTelAvivStockExchange": "N",
    "SignalTradesOnTelAvivStockExchangeIPCV": "0",
    "SignalTradesOnTokyoStockExchange": "N",
    "SignalTradesOnTokyoStockExchangeIPCV": "0",
    "SignalTradesOnTorontoStockExchange": "N",
    "SignalTradesOnTorontoStockExchangeIPCV": "0",
    "SignalTradesOnTSXVentureExchange": "N",
    "SignalTradesOnTSXVentureExchangeIPCV": "0",
    "SignalTradesOnUkraineStockExchange": "N",
    "SignalTradesOnUkraineStockExchangeIPCV": "0",
    "SignalTradesOnUnitedArabEmirates": "N",
    "SignalTradesOnUnitedArabEmiratesIPCV": "0",
    "SignalTradesOnViennaStockExchange": "N",
    "SignalTradesOnViennaStockExchangeIPCV": "0",
    "SignalTradesOnWarsawStockExchange": "N",
    "SignalTradesOnWarsawStockExchangeIPCV": "0",
    "SignalTradesOnZimbabweStockExchange": "N",
    "SignalTradesOnZimbabweStockExchangeIPCV": "0",
    "SignalGeoBusCanada": "N",
    "SignalGeoBusCanadaIPCV": "0",
    "SignalGeoBusMexico": "N",
    "SignalGeoBusMexicoIPCV": "0",
    "SignalGeoBusSouthAmerica": "N",
    "SignalGeoBusSouthAmericaIPCV": "0",
    "SignalGeoBusCentralAmerica": "N",
    "SignalGeoBusCentralAmericaIPCV": "0",
    "SignalGeoBusEurope": "ON",
    "SignalGeoBusEuropeIPCV": "1",
    "SignalGeoBusAfrica": "N",
    "SignalGeoBusAfricaIPCV": "0",
    "SignalGeoBusMiddleEast": "N",
    "SignalGeoBusMiddleEastIPCV": "0",
    "SignalGeoBusAsia": "ON",
    "SignalGeoBusAsiaIPCV": "1",
    "SignalGeoBusAustralasia": "N",
    "SignalGeoBusAustralasiaIPCV": "0",
    "SignalGeoBusCentralAsia": "N",
    "SignalGeoBusCentralAsiaIPCV": "0",
    "SignalGeoBusSouthAsia": "N",
    "SignalGeoBusSouthAsiaIPCV": "0",
    "SignalGeoBusSouthEastAsia": "N",
    "SignalGeoBusSouthEastAsiaIPCV": "0",
    "SignalGeoBusChina": "N",
    "SignalGeoBusChinaIPCV": "0",
    "SignalGeoBusUK": "N",
    "SignalGeoBusUKIPCV": "0",
    "SignalGeoBusJapan": "N",
    "SignalGeoBusJapanIPCV": "0",
    "SignalGeoBusGermany": "N",
    "SignalGeoBusGermanyIPCV": "0",
    "SignalGeoBusAustralia": "N",
    "SignalGeoBusAustraliaIPCV": "0",
    "SignalGeoBusTaiwan": "N",
    "SignalGeoBusTaiwanIPCV": "0",
    "SignalGeoBusFrance": "N",
    "SignalGeoBusFranceIPCV": "0",
    "SignalGeoBusHongKong": "N",
    "SignalGeoBusHongKongIPCV": "0",
    "SignalGeoBusSingapore": "N",
    "SignalGeoBusSingaporeIPCV": "0",
    "SignalGeoBusSouthKorea": "N",
    "SignalGeoBusSouthKoreaIPCV": "0",
    "SignalGeoBusIndia": "N",
    "SignalGeoBusIndiaIPCV": "0",
    "SignalGeoBusMalaysia": "N",
    "SignalGeoBusMalaysiaIPCV": "0",
    "SignalGeoBusUS": "N",
    "SignalGeoBusUSIPCV": "0",
    "SignalTotalLiabilitiesPctIndustry": "N",
    "SignalTotalLiabilitiesPctIndustryIPCV": "0",
    "SignalTotalAssetsPctIndustry": "N",
    "SignalTotalAssetsPctIndustryIPCV": "0",
    "SignalTotalRevenuePctIndustry": "N",
    "SignalTotalRevenuePctIndustryIPCV": "0",
    "SignalMarketValuePctIndustry": "N",
    "SignalMarketValuePctIndustryIPCV": "0",
    "SignalOpIncomePctIndustry": "N",
    "SignalOpIncomePctIndustryIPCV": "0",
    "SignalIncomeBeforeTaxPctIndustry": "N",
    "SignalIncomeBeforeTaxPctIndustryIPCV": "0",
    "SignalNetWorthPctIndustry": "N",
    "SignalNetWorthPctIndustryIPCV": "0",
    "SignalTotalLiabilitiesPct": "N",
    "SignalTotalLiabilitiesPctIPCV": "0",
    "SignalTotalAssetsPct": "N",
    "SignalTotalAssetsPctIPCV": "0",
    "SignalTotalRevenuePct": "N",
    "SignalTotalRevenuePctIPCV": "0",
    "SignalMarketValuePct": "N",
    "SignalMarketValuePctIPCV": "0",
    "SignalOpIncomePct": "N",
    "SignalOpIncomePctIPCV": "0",
    "SignalIncomeBeforeTaxPct": "N",
    "SignalIncomeBeforeTaxPctIPCV": "0",
    "SignalNetWorthPct": "N",
    "SignalNetWorthPctIPCV": "0",
    "SignalMSAAkronOH": "N",
    "SignalMSAAkronOHIPCV": "0"
    }
    }
    ]
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,840
    Rep Power
    480
    Your program works with the data you supplied and my versions of python

    Python 2.7.5+ (default, Sep 19 2013, 13:48:49)
    [GCC 4.8.1] on linux2

    Sorry.
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2014
    Posts
    3
    Rep Power
    0
    Thanks for your reply. sorry, I didn't explain clearly. I need to get and append following data from the file to keyid . How do I do that ?

    can I do like this ?

    for datum in data:
    both.append((datum[u"SequenceID"], datum[u'Data'][u'KeyID'], datum[u'Data'] [u'ReportAvailability'])) ????

    This is the data from the file

    "ReportAvailability":
    {
    "company_directors": "1",
    "company_jobs": "1",
    "company_corporate_family": "1",
    "company_industry_snapshot": "1",
    "company_industry_snapshot_pdf": "1",
    "company_swot": "0",
    "company_credit_us": "1",
    "company_credit_uk": "0",
    "company_strategic": "0",
    "company_analyst_reports": "1",
    "company_valuation_tearsheet": "1",
    "company_chartbook": "1",
    "company_ratios": "1",
    "company_annual": "1",
    "company_financial_health": "1",
    "company_ratio_comparison": "1",
    "company_stock": "1",
    "company_geo_segment": "1",
    "company_income": "1",
    "company_income_as_reported": "1",
    "company_interim_income": "1",
    "company_interim_income_as_reported": "1",
    "company_balance_sheet": "1",
    "company_balance_sheet_as_reported": "1",
    "company_interim_balance_sheet": "1",
    "company_interim_balance_sheet_as_reported": "1",
    "company_cash_flow": "1",
    "company_cash_flow_as_reported": "1",
    "company_interim_cash_flow": "1",
    "company_interim_cash_flow_as_reported": "1"
    },
  6. #4
  7. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,840
    Rep Power
    480
    Looks like the part you want to insert is already there.
    [code]Code tags[/code] are essential for python code and Makefiles!
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2014
    Posts
    3
    Rep Power
    0
    Originally Posted by b49P23TIvg
    Looks like the part you want to insert is already there.
    The file has 50 records with the same type of data ( 1 record as a sample posted above) . If you look at the sample file that has sequenceid, keyid and reportavailabilty { ...} contents. I would like to print from each record sequenceid, keyid and reportavailabilty { ...} contents. But I am not sure how to extract sequenceid, keyid and reportavailabilty { ...} contents three together and print. BTW thanks for looking into my issue

    I want result like this in print output :

    Sequnceid value, keyid value, Reportavailability values

    Thanks
  10. #6
  11. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,840
    Rep Power
    480
    shorten the data carefully, use pprint, show the structure
    Code:
    [{u'Data': {u'AbiNumber': u'115523672',
                u'Address1': u'One AAR Place, 1100 North Wood Dale Road',
                u'KeyID': u'381',
                u'ReportAvailability': {u'company_cash_flow_as_reported': u'1',
                                        u'company_directors': u'1',
                                        u'company_interim_cash_flow': u'1',
                                        u'company_interim_cash_flow_as_reported': u'1',
                                        u'company_jobs': u'1'},
                u'SignalMSAAkronOH': u'N',
                u'SignalMSAAkronOHIPCV': u'0',
                u'SignalNetWorthPctIPCV': u'0',
                u'SignalTrigBankruptcy': u'N',
                u'SignalTrigBankruptcyIPCV': u'0',
                u'VendorFeedID_TollFreePhone': u'70',
                u'YearFounded': u'1966'},
      u'ObjectType': u'2',
      u'SequenceID': u'1'}]
    []brackets denote lists. Lists take integer indexes starting from 0 on the left. {key:value} are dictionaries. Extract a value from the dictionary using its key.
    dictionary[key]


    To get the value of u'company_directors' is
    Code:
    outer_dictionary = data[0]
    nested_dictionary = outer_dictionary[u'Data']
    deeply_nested_dictionary = nested_dictionary[u'ReportAvailability']
    company_directors = deeply_nested_dictionary[u'company_directors']
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo