How can I add image in JSON array - json

please how can I add image to this question. it is written in JSON array.
{
"question": "Nigeria National flag color is?",
"choice1": "Red Black and Gold",
"choice2": "Yellow Gold and Yellow",
"choice3": "Purple Red and Pink",
"choice4": "Green White and Green",
"answer": 4
}

First, convert the image to byte array then add that byte as a JSON value in a JSON key.
example.
Image -> byte array
JSON
{
//... rest of the keys and value
"image": "byte array here"
}
NOTE:
1. if your images are of large size i.e. more than 1MB then use object host(AWS service or other cloud services).
2. Only use the above solution for less than 500KB images.

There are two option for adding image in the JSON :
You can upload your image to the server and get a server link for image, add path to the JSON and then you can show your image to the corresponding view.
You can get directory path for a particular image and add path to the JSON
in both ways JSON will look like this :
{
"question": "https://via.placeholder.com/300.png/09f/fff",
"choice1": "Red Black and Gold",
"choice2": "Yellow Gold and Yellow",
"choice3": "Purple Red and Pink",
"choice4": "Green White and Green",
"answer": 4
}

1.You can base64 image encoding use to it.
https://www.base64encode.org/
{ "question": "Nigeria National flag color is?", "choice1": "Red Black and Gold", "choice2": "Yellow Gold and Yellow", "choice3": "Purple Red and Pink", "choice4": "Green White and Green", "answer": 4 , "image": "base6encodeing" }
In javascript:
Convert image from url to Base64
In c# Convert an image (selected by path) to base64 string
2. Image url use in json.
{ "question": "Nigeria National flag color is?", "choice1": "Red Black and Gold", "choice2": "Yellow Gold and Yellow", "choice3": "Purple Red and Pink", "choice4": "Green White and Green", "answer": 4 , "image": "http:\\mydomain.com\img\upload.jpeg" }

Related

MySQL Combine Group by Column

I am new to SQL statements so my wording per my request may be incorrect, so I will provide a lot of detail to better understand my issue.
I have a database table called workouts that looks like this:
id
bodyPart
gifUrl
name
target
broad_target
1
back
http://d205bpvrqc9yn1.cloudfront.net/0007.gif
alternate lateral pulldown
lats
back
2
chest
http://d205bpvrqc9yn1.cloudfront.net/0009.gif
assisted chest dip (kneeling)
pectorals
chest
3
lower legs
http://d205bpvrqc9yn1.cloudfront.net/1708.gif
assisted lying calves stretch
calves
legs
4
upper legs
http://d205bpvrqc9yn1.cloudfront.net/1709.gif
assisted lying glutes stretch
glutes
legs
5
upper legs
http://d205bpvrqc9yn1.cloudfront.net/1710.gif
assisted lying gluteus and piriformis stretch
glutes
legs
6
back
http://d205bpvrqc9yn1.cloudfront.net/0015.gif
assisted parallel close grip pull-up
lats
back
and I want it to combine all the broad_muscles together and wrap it under an array called data.
Ideally, it would look like this:
{
title: 'Leg',
data:[
{
"bodyPart": "lower legs",
"equipment": "assisted",
"gifUrl": "http://d205bpvrqc9yn1.cloudfront.net/1708.gif",
"id": "1708",
"name": "assisted lying calves stretch",
"target": "calves",
"broad_target": "legs",
"ppl": "legs"
},
{
"bodyPart": "lower legs",
"equipment": "smith machine",
"gifUrl": "http://d205bpvrqc9yn1.cloudfront.net/1396.gif",
"id": "1396",
"name": "smith toe raise",
"target": "calves",
"broad_target": "legs",
"ppl": "legs"
}
]
}
I will return it via. Lambda in Node.JS, so if needed, the answer can be how to parse it in Node.JS.
Thanks!
You can something do like this, but if your o/p formats in an array. You should use any SQL orms that can be helpful.
const sampleData = [{
"id":"1",
"bodyPart":"back",
"gifUrl": "http://d205bpvrqc9yn1.cloudfront.net/0007.gif",
"name": "alternate lateral pulldown" ,
"target": "lats",
"broad_target" : "back"
},{
"id":"2",
"bodyPart":"chest",
"gifUrl": "http://d205bpvrqc9yn1.cloudfront.net/0007.gif",
"name": "assisted chest dip (kneeling)" ,
"target": "pectorals",
"broad_target" : "chest"
},{
"id":"2",
"bodyPart":"upper legs",
"gifUrl": "http://d205bpvrqc9yn1.cloudfront.net/0007.gif",
"name": "assisted chest dip (kneeling)" ,
"target": "glutes",
"broad_target" : "legs"
},{
"id":"2",
"bodyPart":"lower legs",
"gifUrl": "http://d205bpvrqc9yn1.cloudfront.net/0007.gif",
"name": "assisted chest dip (kneeling)" ,
"target": "calves",
"broad_target" : "legs"
}];
const matchString = "legs";
const output = sampleData.reduce((prev, current) => {
if (current?.broad_target === matchString) {
prev['title'] = "Leg";
prev['data'] = (prev['data'] || []);
prev['data'].push(current);
}
return prev
},{});
console.log(output);
Note: I have taken sample o/p as the sample the information might not match the actual data.

How can I retrieve the perimeter and specific geometric properties using the Model Derivative API?

I have followed the Postman tutorial for the model derivative API, specifically for extracting metadata. I used a .dxf file, since I want to know if it is possible to retrieve perimeter, length/width properties based off the file.
I received a 200 response and it gave me a massive list of objects w/ their respective objectid's. Basically I got back a ton of these:
{
"objectid": 253,
"name": "Line [108]",
"externalId": "108",
"properties": {
"3D Visualization ": {
"Material": "ByLayer"
},
"General": {
"Color": "ByLayer",
"Handle": "108",
"Layer": "color#000000ff",
"Linetype": "BYLAYER",
"Linetype scale": "1.000",
"Lineweight": "ByLayer",
"Name ": "Line",
"Plot style": "ByColor",
"Thickness": "0.000 mm",
"Transparency": "ByLayer"
},
"Geometry": {
"Angle": "192.931 deg",
"Length": "0.088 mm"
}
}
}
The .dxf file I tested was as simple as possible and it looks like this image:
How can I retrieve the perimeter of this image? Is it possible to retrieve other specific geometric properties that I specify?
How can I know what part of the .dxf file each objectid is referring to?
Although it looks simple, the polyline (?) is probably being tessellated, resulting in a large number of small lines. Have you tried the original DWG file? Can you try that with viewer.autodesk.com?

How to match JSON-LD markup with REGEX?

I’m attempting to match an entire json-ld entry, regardless of specific markup, line breaks, etc.
Why doesn’t something as simple as this work:
\<script type\=\"application\/ld\+json\"\>(.*?)\<\/script\>
<script type="application/ld+json">
{
"#context": "http://schema.org",
"#type": "Recipe",
"author": "John Smith",
"cookTime": "PT1H",
"datePublished": "2009-05-08",
"description": "This classic banana bread recipe comes from my mom -- the walnuts add a nice texture and flavor to the banana bread.",
"image": "bananabread.jpg",
"recipeIngredient": [
"3 or 4 ripe bananas, smashed",
"1 egg",
"3/4 cup of sugar"
],
"interactionStatistic": {
"#type": "InteractionCounter",
"interactionType": "http://schema.org/Comment",
"userInteractionCount": "140"
},
"name": "Mom's World Famous Banana Bread",
"nutrition": {
"#type": "NutritionInformation",
"calories": "240 calories",
"fatContent": "9 grams fat"
},
"prepTime": "PT15M",
"recipeInstructions": "Preheat the oven to 350 degrees. Mix in the ingredients in a bowl. Add the flour last. Pour the mixture into a loaf pan and bake for one hour.",
"recipeYield": "1 loaf",
"suitableForDiet": "http://schema.org/LowFatDiet"
}
</script>
I expect the output to be everything inside the tag.
Here, we might want to bound our expression with an open json/ld tag as a start boundary, then collect all chars and newlines, and finally add a right boundary with closing script tag, maybe similar to:
(<script type="application\/ld\+json">)([\s\S]*)(<\/script>)
or
^(<script type="application\/ld\+json">)([\w\W]*)(<\/script>)$
DEMO
However, maybe here it would not be the best idea to user regular expressions and there should be so many methods that would do so much easier.
Test
const regex = /^(<script type="application\/ld\+json">)([\w\W]*)(<\/script>)$/gm;
const str = `<script type="application/ld+json">
{
"#context": "http://schema.org",
"#type": "Recipe",
"author": "John Smith",
"cookTime": "PT1H",
"datePublished": "2009-05-08",
"description": "This classic banana bread recipe comes from my mom -- the walnuts add a nice texture and flavor to the banana bread.",
"image": "bananabread.jpg",
"recipeIngredient": [
"3 or 4 ripe bananas, smashed",
"1 egg",
"3/4 cup of sugar"
],
"interactionStatistic": {
"#type": "InteractionCounter",
"interactionType": "http://schema.org/Comment",
"userInteractionCount": "140"
},
"name": "Mom's World Famous Banana Bread",
"nutrition": {
"#type": "NutritionInformation",
"calories": "240 calories",
"fatContent": "9 grams fat"
},
"prepTime": "PT15M",
"recipeInstructions": "Preheat the oven to 350 degrees. Mix in the ingredients in a bowl. Add the flour last. Pour the mixture into a loaf pan and bake for one hour.",
"recipeYield": "1 loaf",
"suitableForDiet": "http://schema.org/LowFatDiet"
}
</script>`;
const subst = `$2`;
// The substituted value will be contained in the result variable
const result = str.replace(regex, subst);
console.log('Substitution result: ', result);
DEMO
RegEx
If this expression wasn't desired, it can be modified or changed in regex101.com.
RegEx Circuit
jex.im visualizes regular expressions:

working with advavced json data anjular js

i am new to anjular js , i know how to work with basic json data with anjular js.
i have nauseated json data
[
{
"activity_user": "asd#gmail.com",
"home_id": "1",
"recent_connect_address": "South Hill Road, Callington, Cornwall ",
"recent_connect_postcode": "WA3 1PQ",
"propertyimg": "a.jpg",
"datemovein": "2014-12-04 00:00:00",
"datemoveout": "2016-12-29 00:00:00",
"list": "[{ comment:\"The $190 Bonavita 1900TS made better coffee than the other machines, according to our 10-person tasting panel. \", date:\"2014-12-01 00:00:00\"},{ comment:\"The $190 Bonavita 1900TS made better coffee than the other machines, according to our 10-person tasting panel. \", date:\"2014-12-01 00:00:00\"}]"
},
{
"activity_user": "asd525#gmail.com",
"home_id": "2",
"recent_connect_address": "548 Newton Road, Lowton, Warrington ",
"recent_connect_postcode": "PL17 7LH",
"propertyimg": "a.jpg",
"datemovein": "2014-12-01 00:00:00",
"datemoveout": "2014-12-31 00:00:00",
"list": "[{ comment:\"We considered 80 Champagne glasses before testing 10 glasses for 12 hours, and we found that the Schott Zwiesel 1872 Enoteca is best for most people. It’s taller, lighter, and thinner than any glass we tried, with tiny etching to keep Champagne carbonated longer. The tulip shape allows more aromas to reach your nose while still maintaining an elegant profile.\", date:\"2014-12-31 00:00:00\"}]"
}
]
now i want to print it out following format
<div class="row" ng-controller="ListCtrl">
<div ng-repeat="property in timeline" >
<div>{{property.activity_user}}</div>
<div class="comments">
<div>{{property.list.}}</div>
</div>
</div>
here is my controller but it not work
function ListCtrl($scope, $http) {
$http({method: 'GET', url: 'my.json'}).success(function(data) {
$scope.timeline = data;
});
};
i refer Accesing nested JSON with AngularJS but i didn't understand it
There are several problems in your code right now:
DEMO
The interpolated value inside your ng-repeat for the property.list has a dot in it:
change
<div>{{property.list.}}</div>
to
<div>{{property.list}}</div>
You are missing a div element in your html for closing the top level div.
You are declaring your controllers in a global manner, this is already deprecated and no longer recommended as of AngularJS 1.3. See documentation Arguments Section.
Instead of declaring it like this:
function ListCtrl() {}
You can do this instead:
angular.module('yourApp', [])
.controller('ListCtrl', function() {});
The list property is a string, not an array of objects representing comments.
I suggest you change its structure to something like this:
"list": [
{
"comment": "The $190 Bonavita 1900TS made better coffee than the other machines, according to our 10-person tasting panel. ",
"date":"2014-12-01 00:00:00"
},
{
"comment": "The $190 Bonavita 1900TS made better coffee than the other machines, according to our 10-person tasting panel. ",
"date":"2014-12-01 00:00:00"
}]
Javascript
angular.module('demo', [])
.controller('ListCtrl', function($scope, $http) {
$http({method: 'GET', url: 'my.json'}).success(function(data) {
$scope.timeline = data;
});
});
HTML
<div class="row" ng-controller="ListCtrl">
<div ng-repeat="property in timeline">
<div>{{property.activity_user}}</div>
<div class="comments">
<div ng-repeat="item in property.list">
<div>{{item.comment}}</div>
<em>-- {{item.date}}</em>
</div>
</div>
</div>
</div>
my.json
[
{
"activity_user": "asd#gmail.com",
"home_id": "1",
"recent_connect_address": "South Hill Road, Callington, Cornwall ",
"recent_connect_postcode": "WA3 1PQ",
"propertyimg": "a.jpg",
"datemovein": "2014-12-04 00:00:00",
"datemoveout": "2016-12-29 00:00:00",
"list": [
{
"comment": "The $190 Bonavita 1900TS made better coffee than the other machines, according to our 10-person tasting panel. ",
"date":"2014-12-01 00:00:00"
},
{
"comment": "The $190 Bonavita 1900TS made better coffee than the other machines, according to our 10-person tasting panel. ",
"date":"2014-12-01 00:00:00"
}
]
},
{
"activity_user": "asd525#gmail.com",
"home_id": "2",
"recent_connect_address": "548 Newton Road, Lowton, Warrington ",
"recent_connect_postcode": "PL17 7LH",
"propertyimg": "a.jpg",
"datemovein": "2014-12-01 00:00:00",
"datemoveout": "2014-12-31 00:00:00",
"list": [
{
"comment": "We considered 80 Champagne glasses before testing 10 glasses for 12 hours, and we found that the Schott Zwiesel 1872 Enoteca is best for most people. It’s taller, lighter, and thinner than any glass we tried, with tiny etching to keep Champagne carbonated longer. The tulip shape allows more aromas to reach your nose while still maintaining an elegant profile",
"date":"2014-12-31 00:00:0"
}
]
}
]
If you re using ( $scope.timeline ), that means you must use in html :
{{timeline[0].activity_user}} // print: asd#gmail.com

JSON- categorical data

I am writing a JSON file which holds data about electronics such as tvs, consoles etc. What is the best way to categorize, let's say 3D LED tvs, from non 3D LED tvs ? Would it make more sense to put a property '3d' within an 'leds' object ? Or is it better to create a '3d' object within 'leds' ?
{"products":[
{ "tvs":[
{"samsung":[
{"leds":[
{
"product_id": "034567",
"product_name": "Samsung UA22F5100 22'' LED TV (Black)",
"model_no": "UA22F5100",
"brand": "Samsung",
"price": 399,
"screen_size": 22,
"screen_res": "1920 x 1080",
"usb": 1,
"hdmi": 1,
"screen_format": "LED",
"dimensions": "513.1 x 366.5 x 169.6",
"manuf_guarantee": "1 year"
}
]}
]}
]}
]}