google spreadsheet export into json file, how to format? - javascript

I am following the tutorials that can help extract my google spreadsheet to a json file http://blog.pamelafox.org/2013/06/exporting-google-spreadsheet-as-json.html . But I have a list of object in some of the google spreadsheet cell. My one of my spreadsheet is like this: screenshot http://www.tianyuwu.com/wp-content/uploads/2014/09/Screen-Shot-2014-09-22-at-11.46.00-PM.png.
What I expert is to make the json file like this.
{
"features": "*articles\n*archive\n*video\n*search\n*social",
"data": "*news feeds\n*oroeco team",
"content": "* blog posts\n* analysis\n* screen shots",
}
But what I expect is like this
{
"features": "articles","archive","video", "search", "social",
"data": "news feeds","oroeco team",
"content": "* blog posts","analysis", "screen shots",
}
What is the most efficient way to convert?

If you're using JavaScript, try this:
json_original = {
"features" : "*articles\n*archive\n*video\n*search\n*social",
"data" : "*news feeds\n*oroeco team",
"content" : "* blog posts\n* analysis\n* screen shots",
}
json_formated = {}
for (var p in json_original) {
json_formated[p] = json_original[p].replace('\n', '').split('*').map(function(x) { return x.trim(); }).filter(function(x) {return x != ''; });
}

Related

How to note data source in a data JSON file?

I have a few data JSON files similar to this and I want to include a line to note the sources as simple as //source: Cambodia Department of Injustice but JSON files should contain only data.
Should should it be done?
If you can change the data structure slightly, you could add a level for metadata:
{
"metadata": {
"source": "Cambodia Department of Justice",
"source-date": "2015-12-15",
"note": "Ha ha made you look"
},
"countries": {
"USA": { some data }
"Canada": { Some data }
}
}
This is cleaner than use a fake "non-data" country.

Wix Velo — How to work with Array of Object

I'm currently building a website on Wix, and have come across a problem I can't think myself out of. Neither Wix support or the Wix Velo Forum have been able to help me out.
I have a repeater that is connected to the Stores/Products collection, and in the Stores/Products collection there's a collection field that contains additional info sections on the product. I have three info section; Tempo, Genre and Tags. Each contains a description.
It looks like this:
[
{
"title": "Tempo",
"description": "<p>142 BPM</p>\n"
},
{
"title": "Genre",
"description": "<p>Jazz</p>\n"
},
{
"title": "Tags",
"description": "<p>Frank Ocean, Travis Scott</p>\n"
}
]
I have figured out how to pull the individual objects with this code:
export function audioRepeater_itemReady($item, itemData, index) {
let product = $item('#dataset3').getCurrentItem(itemData._id)
let ArrayAdditionalInfo = []
ArrayAdditionalInfo = product.additionalInfoSections
ArrayAdditionalInfo.forEach((element) => {
console.log(element.title)
console.log(element.description)
})
But I want it to be able to figure out if eg. the Title === "Genre", then it will show the description from that array, like this:
{
// if equal to this:
"title": "Genre",
// show me this
"description": "<p>Jazz</p>\n"
},
The whole plan with this is to show the description output in a text element that I can implement in the repeater.
I have tried with if statements, but I just can't put it together myself. If this is confusing I'll gladly elaborate.
Thank you in advance.
I'm not a 100% sure if I understood the question correctly, but if you want to show all titles, and, conditionally the description if the title is Genre, you could just use a Ternary:
let data = [{
"title": "Tempo",
"description": "142 BPM\n"
},{
"title": "Genre",
"description": "Jazz\n"
},{
"title": "Tags",
"description": "Frank Ocean, Travis Scott\n"
}];
data.forEach(e => $("#products").append(
`<p>Title: ${e.title}${
e.title === "Genre"
? "<br>description: " + e.description
: ""
}</p>`
));
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="products">
</div>
I think your issue related to handler. You use repeaters onItemReady handler, which is not the best option for your case. It calls for each row in repeater. Instead of this I recommend to use dataset's onReady
$w("#dataset3").onReady( () => {
console.log("The dataset is ready");
$w("#audioRepeater").getItems(0, 20).then( (result) => {
let items = result.items;
items.forEach((element) => {
if (element.title === 'Genre') {
doWhatDoYouWant(element)
}
})
} ).catch( (err) => {
let errMsg = err.message;
let errCode = err.code;
} );
} );
Please take into consideration that this block should be inserted into $w.onReady

Adaptive card(user input form) in BotFramework V4 nodejs gets reprompted after user submit

async feed_first(stepContext)
{
let company_card = MessageFactory.attachment(
CardFactory.adaptiveCard(testfeedback)
);
return await stepContext.prompt("textPrompt", {
prompt: company_card
});
}
async feed_second(stepContext) {
console.log("enter feedback second");
console.log(stepContext.context.activity.value);
}
{
"type": "AdaptiveCard",
"version": "1.0",
"body": [
{
"type": "Container",
"items": [
{
"type": "Input.ChoiceSet",
"placeholder": "Placeholder text",
"choices": [
{
"title": " 1",
"value": " 1"
},
{
"title": " 2",
"value": " 2"
}
],
"style": "expanded",
"id": "cho"
},
{
"type": "ActionSet",
"actions": [
{
"type": "Action.Submit",
"title": "Submit"
}
]
}
]
}
],
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json"
}
so for this code what happens is, the card gets displayed, but on the bot emulator when the submit button is clicked, nothing happens. the console displays " Running dialog with message activity" and the same card is prompted again. the bot doesn't flow to the second step(feed_second) of waterfall dialog. what i would like for the code to do is to display "enter feedback second" on the console and then show the selected choice with the id "cho" for stepContext.context.activity.value agiain on the console. side note- i have added "feed_first" and "feed_second" while declaring the WaterfallDialog, so that's not the the issue
If you want to use an Adaptive Card's inputs with a text prompt, you will need to access the activity's value and serialize it into the activity's text somehow, as seen in this example. This information is in the dialogs section of my Adaptive Cards blog post, which you should read.
In JavaScript you can serialize the value into text like this:
/**
*
* #param {TurnContext} turnContext
*/
async sendValueToDialogAsync(turnContext)
{
// Serialize value
var json = JSON.stringify(turnContext.activity.value);
// Assign the serialized value to the turn context's activity
turnContext.activity.text = json;
// Create a dialog context
var dc = await this.dialogs.createContext(turnContext);
// Continue the dialog with the modified activity
await dc.continueDialog();
}
In your case, if you only need the result of one input then you can just use that property instead of serializing anything:
turnContext.activity.text = turnContext.activity.value.cho;

JavaScript google gapi spreadsheets.create not setting title, using 'Untitled speadsheet'

When I use the following, the sheet is created, but the title isn't being set.
When I use the api explorer, it creates with the right title. Using this documentation:
https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/create?apix_params=%7B%22resource%22%3A%7B%22properties%22%3A%7B%22title%22%3A%22x%22%7D%7D%7D
var request = gapi.client.sheets.spreadsheets.create({ "properties": { "title": "x" } }, {});
in the response:
...
title: "Untitled spreadsheet"
...
var request = gapi.client.sheets.spreadsheets.create({ "properties": { "title": "x" } });
Removing the second object was all I needed.

Angular-Schema-Form Change FORM on SCHEMA change

I have got a problem with changing json schema with angular schema form.
If I set up schema like in code like this
$scope.schema = {
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Schema number ONE",
"type": "object",
"properties": {..
it works and renders whole form properly as I want.
But I want to load data from web service.
So I tried to set up schema to nothing and then change it by clicking button, but it didnt work. I mean, i got schema from service, but form do not change.
For example something like this in code.
$scope.schema = {};
$scope.changeSchema= function(){
$scope.schema = {
"$schema": "http://json-schema.org/draft-04/schema#",
"title": " Schema number two that I want",
"type": "object",
"properties": {
}
What I want is to select schema to load and change form to schema i selected.
Thank you very much.
As Claies pointed out in their comment, you need to trigger a schemaFormRedraw broadcast. However on load the error is due to validation on the schema that you have as {}, this would need to be a temporary schema, something along these lines should work:
$scope.schema = { "type": "object", "properties": {} }};
$scope.changeSchema = function() {
$scope.schema = {
"$schema": "http://json-schema.org/draft-04/schema#",
"title": " Schema number two that I want",
"type": "object",
"properties": {...}
}
$scope.$broadcast('schemaFormRedraw');
}

Categories