How to parse from JSONP file using Python3?





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















This my first time messing with .json/.jsonp files and I have multiple .jsonp files in a folder that I need to parse key values from. From my understanding I need to convert jsonp to json then use the key to get the associated value, but can't seem to figure out how to successfully load my jsonp file with python3 then convert it to json.



I can read the file with just a basic open and read, but it seems like the wrong way to read it. If that's fine then what is the best way to convert it?



How I'm reading it:



jsonp=open(r'''C:Userszburc_000Desktopobserved_otus_significancecolumn-african_american.jsonp''','r')


What the file looks like:



load_data('amount_fat_free_milk',{"name":null,"index":["12oz (n=10)","16oz (n=7)","20oz (n=2)","6 oz or less8 oz oz (n=1)","8oz (n=27)","NA (n=225)","less than 6oz (n=24)","more than 20oz (n=54)"],"data":[[54,47,19,64,74,61,72,52,31,30],[38,77,129,34,38,39,82],[51,39],[39],[29,53,47,74,62,36,40,39,32,63,41,139,72,156,27,43,25,95,65,23,45,72,108,85,33,82,65],[70,48,68,121,58,90,45,62,52,136,56,93,76,84,53,82,92,84,26,53,50,109,81,58,84,54,61,69,55,59,41,54,66,96,66,80,42,59,44,56,58,33,26,51,69,48,93,103,55,79,76,41,96,71,56,26,98,51,60,59,60,33,63,50,45,45,69,127,65,94,32,38,102,86,59,85,30,102,117,95,55,44,71,86,36,102,67,40,54,81,66,45,83,25,91,76,42,27,46,75,86,89,42,59,60,49,65,57,37,57,49,42,35,54,38,77,54,57,95,34,51,78,47,91,97,78,62,53,41,59,55,37,55,114,31,87,54,56,56,53,63,29,34,34,47,32,123,76,35,29,34,54,62,80,60,45,37,62,36,28,40,62,56,71,47,40,97,47,58,53,45,36,63,36,85,86,100,36,53,37,37,28,48,73,70,83,50,78,95,46,52,16,70,105,71,79,51,66,77,47,47,154,100,60,77,46,86,69,43,64,38,22,75,33,45,68,35,43,67,141,45,49,60,87,103],[26,122,98,99,38,61,116,42,51,67,32,117,135,63,47,21,56,24,55,61,69,40,100,30],[20,77,23,43,37,56,171,55,135,130,52,123,80,67,107,41,75,72,42,44,27,87,104,47,69,64,17,84,30,26,117,53,29,49,45,20,76,116,46,77,15,47,96,83,39,36,133,27,168,30,49,42,34,45]]},{"initial": 350, "filtered": 350},{"p": 0.6810926316972944, "H": 4.826778985767726},' H p-value q-value Group 1 Group 2 12oz (n=10) 16oz (n=7) 0.467239 0.494260 0.891202 20oz (n=2) 0.415385 0.519249 0.891202 6 oz or less8 oz oz (n=1) 0.400000 0.527089 0.891202 8oz (n=27) 0.379262 0.537998 0.891202 NA (n=225) 1.728250 0.188635 0.891202 less than 6oz (n=24) 0.692063 0.405464 0.891202 more than 20oz (n=54) 0.407082 0.523455 0.891202 16oz (n=7) 20oz (n=2) 0.021792 0.882642 0.988559 6 oz or less8 oz oz (n=1) 0.000000 1.000000 1.000000 8oz (n=27) 0.000454 0.983003 1.000000 NA (n=225) 0.267899 0.604744 0.891202 less than 6oz (n=24) 0.055860 0.813163 0.988559 more than 20oz (n=54) 0.032782 0.856322 0.988559 20oz (n=2) 6 oz or less8 oz oz (n=1) 0.500000 0.479500 0.891202 8oz (n=27) 0.313194 0.575727 0.891202 NA (n=225) 1.339476 0.247126 0.891202 less than 6oz (n=24) 0.669439 0.413247 0.891202 more than 20oz (n=54) 0.304675 0.580967 0.891202 6 oz or less8 oz oz (n=1) 8oz (n=27) 0.552177 0.457429 0.891202 NA (n=225) 1.304423 0.253407 0.891202 less than 6oz (n=24) 0.692574 0.405290 0.891202 more than 20oz (n=54) 0.620241 0.430958 0.891202 8oz (n=27) NA (n=225) 0.889579 0.345591 0.891202 less than 6oz (n=24) 0.115421 0.734055 0.988559 more than 20oz (n=54) 0.075931 0.782890 0.988559 NA (n=225) less than 6oz (n=24) 0.000720 0.978590 1.000000 more than 20oz (n=54) 0.756352 0.384473 0.891202 less than 6oz (n=24) more than 20oz (n=54) 0.098603 0.753513 0.988559 ','kruskal-wallis-pairwise-amount_fat_free_milk.csv', 'observed_otus');



Ultimately I need to be able to get the values from the "p" and "H" but my main problem right now is getting it converted to json.










share|improve this question























  • You need to strip out the "padding" before parsing as JSON, see e.g. stackoverflow.com/questions/30554522/…

    – jonrsharpe
    Jan 3 at 16:55


















0















This my first time messing with .json/.jsonp files and I have multiple .jsonp files in a folder that I need to parse key values from. From my understanding I need to convert jsonp to json then use the key to get the associated value, but can't seem to figure out how to successfully load my jsonp file with python3 then convert it to json.



I can read the file with just a basic open and read, but it seems like the wrong way to read it. If that's fine then what is the best way to convert it?



How I'm reading it:



jsonp=open(r'''C:Userszburc_000Desktopobserved_otus_significancecolumn-african_american.jsonp''','r')


What the file looks like:



load_data('amount_fat_free_milk',{"name":null,"index":["12oz (n=10)","16oz (n=7)","20oz (n=2)","6 oz or less8 oz oz (n=1)","8oz (n=27)","NA (n=225)","less than 6oz (n=24)","more than 20oz (n=54)"],"data":[[54,47,19,64,74,61,72,52,31,30],[38,77,129,34,38,39,82],[51,39],[39],[29,53,47,74,62,36,40,39,32,63,41,139,72,156,27,43,25,95,65,23,45,72,108,85,33,82,65],[70,48,68,121,58,90,45,62,52,136,56,93,76,84,53,82,92,84,26,53,50,109,81,58,84,54,61,69,55,59,41,54,66,96,66,80,42,59,44,56,58,33,26,51,69,48,93,103,55,79,76,41,96,71,56,26,98,51,60,59,60,33,63,50,45,45,69,127,65,94,32,38,102,86,59,85,30,102,117,95,55,44,71,86,36,102,67,40,54,81,66,45,83,25,91,76,42,27,46,75,86,89,42,59,60,49,65,57,37,57,49,42,35,54,38,77,54,57,95,34,51,78,47,91,97,78,62,53,41,59,55,37,55,114,31,87,54,56,56,53,63,29,34,34,47,32,123,76,35,29,34,54,62,80,60,45,37,62,36,28,40,62,56,71,47,40,97,47,58,53,45,36,63,36,85,86,100,36,53,37,37,28,48,73,70,83,50,78,95,46,52,16,70,105,71,79,51,66,77,47,47,154,100,60,77,46,86,69,43,64,38,22,75,33,45,68,35,43,67,141,45,49,60,87,103],[26,122,98,99,38,61,116,42,51,67,32,117,135,63,47,21,56,24,55,61,69,40,100,30],[20,77,23,43,37,56,171,55,135,130,52,123,80,67,107,41,75,72,42,44,27,87,104,47,69,64,17,84,30,26,117,53,29,49,45,20,76,116,46,77,15,47,96,83,39,36,133,27,168,30,49,42,34,45]]},{"initial": 350, "filtered": 350},{"p": 0.6810926316972944, "H": 4.826778985767726},' H p-value q-value Group 1 Group 2 12oz (n=10) 16oz (n=7) 0.467239 0.494260 0.891202 20oz (n=2) 0.415385 0.519249 0.891202 6 oz or less8 oz oz (n=1) 0.400000 0.527089 0.891202 8oz (n=27) 0.379262 0.537998 0.891202 NA (n=225) 1.728250 0.188635 0.891202 less than 6oz (n=24) 0.692063 0.405464 0.891202 more than 20oz (n=54) 0.407082 0.523455 0.891202 16oz (n=7) 20oz (n=2) 0.021792 0.882642 0.988559 6 oz or less8 oz oz (n=1) 0.000000 1.000000 1.000000 8oz (n=27) 0.000454 0.983003 1.000000 NA (n=225) 0.267899 0.604744 0.891202 less than 6oz (n=24) 0.055860 0.813163 0.988559 more than 20oz (n=54) 0.032782 0.856322 0.988559 20oz (n=2) 6 oz or less8 oz oz (n=1) 0.500000 0.479500 0.891202 8oz (n=27) 0.313194 0.575727 0.891202 NA (n=225) 1.339476 0.247126 0.891202 less than 6oz (n=24) 0.669439 0.413247 0.891202 more than 20oz (n=54) 0.304675 0.580967 0.891202 6 oz or less8 oz oz (n=1) 8oz (n=27) 0.552177 0.457429 0.891202 NA (n=225) 1.304423 0.253407 0.891202 less than 6oz (n=24) 0.692574 0.405290 0.891202 more than 20oz (n=54) 0.620241 0.430958 0.891202 8oz (n=27) NA (n=225) 0.889579 0.345591 0.891202 less than 6oz (n=24) 0.115421 0.734055 0.988559 more than 20oz (n=54) 0.075931 0.782890 0.988559 NA (n=225) less than 6oz (n=24) 0.000720 0.978590 1.000000 more than 20oz (n=54) 0.756352 0.384473 0.891202 less than 6oz (n=24) more than 20oz (n=54) 0.098603 0.753513 0.988559 ','kruskal-wallis-pairwise-amount_fat_free_milk.csv', 'observed_otus');



Ultimately I need to be able to get the values from the "p" and "H" but my main problem right now is getting it converted to json.










share|improve this question























  • You need to strip out the "padding" before parsing as JSON, see e.g. stackoverflow.com/questions/30554522/…

    – jonrsharpe
    Jan 3 at 16:55














0












0








0








This my first time messing with .json/.jsonp files and I have multiple .jsonp files in a folder that I need to parse key values from. From my understanding I need to convert jsonp to json then use the key to get the associated value, but can't seem to figure out how to successfully load my jsonp file with python3 then convert it to json.



I can read the file with just a basic open and read, but it seems like the wrong way to read it. If that's fine then what is the best way to convert it?



How I'm reading it:



jsonp=open(r'''C:Userszburc_000Desktopobserved_otus_significancecolumn-african_american.jsonp''','r')


What the file looks like:



load_data('amount_fat_free_milk',{"name":null,"index":["12oz (n=10)","16oz (n=7)","20oz (n=2)","6 oz or less8 oz oz (n=1)","8oz (n=27)","NA (n=225)","less than 6oz (n=24)","more than 20oz (n=54)"],"data":[[54,47,19,64,74,61,72,52,31,30],[38,77,129,34,38,39,82],[51,39],[39],[29,53,47,74,62,36,40,39,32,63,41,139,72,156,27,43,25,95,65,23,45,72,108,85,33,82,65],[70,48,68,121,58,90,45,62,52,136,56,93,76,84,53,82,92,84,26,53,50,109,81,58,84,54,61,69,55,59,41,54,66,96,66,80,42,59,44,56,58,33,26,51,69,48,93,103,55,79,76,41,96,71,56,26,98,51,60,59,60,33,63,50,45,45,69,127,65,94,32,38,102,86,59,85,30,102,117,95,55,44,71,86,36,102,67,40,54,81,66,45,83,25,91,76,42,27,46,75,86,89,42,59,60,49,65,57,37,57,49,42,35,54,38,77,54,57,95,34,51,78,47,91,97,78,62,53,41,59,55,37,55,114,31,87,54,56,56,53,63,29,34,34,47,32,123,76,35,29,34,54,62,80,60,45,37,62,36,28,40,62,56,71,47,40,97,47,58,53,45,36,63,36,85,86,100,36,53,37,37,28,48,73,70,83,50,78,95,46,52,16,70,105,71,79,51,66,77,47,47,154,100,60,77,46,86,69,43,64,38,22,75,33,45,68,35,43,67,141,45,49,60,87,103],[26,122,98,99,38,61,116,42,51,67,32,117,135,63,47,21,56,24,55,61,69,40,100,30],[20,77,23,43,37,56,171,55,135,130,52,123,80,67,107,41,75,72,42,44,27,87,104,47,69,64,17,84,30,26,117,53,29,49,45,20,76,116,46,77,15,47,96,83,39,36,133,27,168,30,49,42,34,45]]},{"initial": 350, "filtered": 350},{"p": 0.6810926316972944, "H": 4.826778985767726},' H p-value q-value Group 1 Group 2 12oz (n=10) 16oz (n=7) 0.467239 0.494260 0.891202 20oz (n=2) 0.415385 0.519249 0.891202 6 oz or less8 oz oz (n=1) 0.400000 0.527089 0.891202 8oz (n=27) 0.379262 0.537998 0.891202 NA (n=225) 1.728250 0.188635 0.891202 less than 6oz (n=24) 0.692063 0.405464 0.891202 more than 20oz (n=54) 0.407082 0.523455 0.891202 16oz (n=7) 20oz (n=2) 0.021792 0.882642 0.988559 6 oz or less8 oz oz (n=1) 0.000000 1.000000 1.000000 8oz (n=27) 0.000454 0.983003 1.000000 NA (n=225) 0.267899 0.604744 0.891202 less than 6oz (n=24) 0.055860 0.813163 0.988559 more than 20oz (n=54) 0.032782 0.856322 0.988559 20oz (n=2) 6 oz or less8 oz oz (n=1) 0.500000 0.479500 0.891202 8oz (n=27) 0.313194 0.575727 0.891202 NA (n=225) 1.339476 0.247126 0.891202 less than 6oz (n=24) 0.669439 0.413247 0.891202 more than 20oz (n=54) 0.304675 0.580967 0.891202 6 oz or less8 oz oz (n=1) 8oz (n=27) 0.552177 0.457429 0.891202 NA (n=225) 1.304423 0.253407 0.891202 less than 6oz (n=24) 0.692574 0.405290 0.891202 more than 20oz (n=54) 0.620241 0.430958 0.891202 8oz (n=27) NA (n=225) 0.889579 0.345591 0.891202 less than 6oz (n=24) 0.115421 0.734055 0.988559 more than 20oz (n=54) 0.075931 0.782890 0.988559 NA (n=225) less than 6oz (n=24) 0.000720 0.978590 1.000000 more than 20oz (n=54) 0.756352 0.384473 0.891202 less than 6oz (n=24) more than 20oz (n=54) 0.098603 0.753513 0.988559 ','kruskal-wallis-pairwise-amount_fat_free_milk.csv', 'observed_otus');



Ultimately I need to be able to get the values from the "p" and "H" but my main problem right now is getting it converted to json.










share|improve this question














This my first time messing with .json/.jsonp files and I have multiple .jsonp files in a folder that I need to parse key values from. From my understanding I need to convert jsonp to json then use the key to get the associated value, but can't seem to figure out how to successfully load my jsonp file with python3 then convert it to json.



I can read the file with just a basic open and read, but it seems like the wrong way to read it. If that's fine then what is the best way to convert it?



How I'm reading it:



jsonp=open(r'''C:Userszburc_000Desktopobserved_otus_significancecolumn-african_american.jsonp''','r')


What the file looks like:



load_data('amount_fat_free_milk',{"name":null,"index":["12oz (n=10)","16oz (n=7)","20oz (n=2)","6 oz or less8 oz oz (n=1)","8oz (n=27)","NA (n=225)","less than 6oz (n=24)","more than 20oz (n=54)"],"data":[[54,47,19,64,74,61,72,52,31,30],[38,77,129,34,38,39,82],[51,39],[39],[29,53,47,74,62,36,40,39,32,63,41,139,72,156,27,43,25,95,65,23,45,72,108,85,33,82,65],[70,48,68,121,58,90,45,62,52,136,56,93,76,84,53,82,92,84,26,53,50,109,81,58,84,54,61,69,55,59,41,54,66,96,66,80,42,59,44,56,58,33,26,51,69,48,93,103,55,79,76,41,96,71,56,26,98,51,60,59,60,33,63,50,45,45,69,127,65,94,32,38,102,86,59,85,30,102,117,95,55,44,71,86,36,102,67,40,54,81,66,45,83,25,91,76,42,27,46,75,86,89,42,59,60,49,65,57,37,57,49,42,35,54,38,77,54,57,95,34,51,78,47,91,97,78,62,53,41,59,55,37,55,114,31,87,54,56,56,53,63,29,34,34,47,32,123,76,35,29,34,54,62,80,60,45,37,62,36,28,40,62,56,71,47,40,97,47,58,53,45,36,63,36,85,86,100,36,53,37,37,28,48,73,70,83,50,78,95,46,52,16,70,105,71,79,51,66,77,47,47,154,100,60,77,46,86,69,43,64,38,22,75,33,45,68,35,43,67,141,45,49,60,87,103],[26,122,98,99,38,61,116,42,51,67,32,117,135,63,47,21,56,24,55,61,69,40,100,30],[20,77,23,43,37,56,171,55,135,130,52,123,80,67,107,41,75,72,42,44,27,87,104,47,69,64,17,84,30,26,117,53,29,49,45,20,76,116,46,77,15,47,96,83,39,36,133,27,168,30,49,42,34,45]]},{"initial": 350, "filtered": 350},{"p": 0.6810926316972944, "H": 4.826778985767726},' H p-value q-value Group 1 Group 2 12oz (n=10) 16oz (n=7) 0.467239 0.494260 0.891202 20oz (n=2) 0.415385 0.519249 0.891202 6 oz or less8 oz oz (n=1) 0.400000 0.527089 0.891202 8oz (n=27) 0.379262 0.537998 0.891202 NA (n=225) 1.728250 0.188635 0.891202 less than 6oz (n=24) 0.692063 0.405464 0.891202 more than 20oz (n=54) 0.407082 0.523455 0.891202 16oz (n=7) 20oz (n=2) 0.021792 0.882642 0.988559 6 oz or less8 oz oz (n=1) 0.000000 1.000000 1.000000 8oz (n=27) 0.000454 0.983003 1.000000 NA (n=225) 0.267899 0.604744 0.891202 less than 6oz (n=24) 0.055860 0.813163 0.988559 more than 20oz (n=54) 0.032782 0.856322 0.988559 20oz (n=2) 6 oz or less8 oz oz (n=1) 0.500000 0.479500 0.891202 8oz (n=27) 0.313194 0.575727 0.891202 NA (n=225) 1.339476 0.247126 0.891202 less than 6oz (n=24) 0.669439 0.413247 0.891202 more than 20oz (n=54) 0.304675 0.580967 0.891202 6 oz or less8 oz oz (n=1) 8oz (n=27) 0.552177 0.457429 0.891202 NA (n=225) 1.304423 0.253407 0.891202 less than 6oz (n=24) 0.692574 0.405290 0.891202 more than 20oz (n=54) 0.620241 0.430958 0.891202 8oz (n=27) NA (n=225) 0.889579 0.345591 0.891202 less than 6oz (n=24) 0.115421 0.734055 0.988559 more than 20oz (n=54) 0.075931 0.782890 0.988559 NA (n=225) less than 6oz (n=24) 0.000720 0.978590 1.000000 more than 20oz (n=54) 0.756352 0.384473 0.891202 less than 6oz (n=24) more than 20oz (n=54) 0.098603 0.753513 0.988559 ','kruskal-wallis-pairwise-amount_fat_free_milk.csv', 'observed_otus');



Ultimately I need to be able to get the values from the "p" and "H" but my main problem right now is getting it converted to json.







json python-3.x parsing jsonp






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 3 at 16:48









Zach BurchamZach Burcham

11




11













  • You need to strip out the "padding" before parsing as JSON, see e.g. stackoverflow.com/questions/30554522/…

    – jonrsharpe
    Jan 3 at 16:55



















  • You need to strip out the "padding" before parsing as JSON, see e.g. stackoverflow.com/questions/30554522/…

    – jonrsharpe
    Jan 3 at 16:55

















You need to strip out the "padding" before parsing as JSON, see e.g. stackoverflow.com/questions/30554522/…

– jonrsharpe
Jan 3 at 16:55





You need to strip out the "padding" before parsing as JSON, see e.g. stackoverflow.com/questions/30554522/…

– jonrsharpe
Jan 3 at 16:55












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54026493%2fhow-to-parse-from-jsonp-file-using-python3%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54026493%2fhow-to-parse-from-jsonp-file-using-python3%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

'app-layout' is not a known element: how to share Component with different Modules

android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

WPF add header to Image with URL pettitions [duplicate]