You'd have to do JSON.parse(conversations.messages[0]).text. This way you parse the object inside messages and have access to its properties.
You'd have to do JSON.parse(conversations.messages[0]).text. This way you parse the object inside messages and have access to its properties.
Simply JSON.parse the string
var myJson = "[{\"id\":72,\"food_item_id\":\"56\",\"variation_id\":\"20\",\"price\":\"50\",\"created_at\":\"2021-06-29T05:29:14.000000Z\",\"updated_at\":\"2021-06-29T05:29:14.000000Z\",\"variant\":null}]";
var myJson2 = JSON.parse(myJson);
console.log(myJson2);
I am not good with vue. But from you code I can say you have issue with objects. You cann't access to value with dot notation if value name is invalid javascript variable name. Use it like this.
<ul id="Nodes">
<li v-for="node in json.Nodes">
{{ node['@type'] }}
{{ node['@group'] }}
{{ node['@name'] }}
<li v-for="item in node.Items">
{{ item['@name'] }}
{{ item['@defaultValue'] }}
{{ item.['@expression'] }}
{{ item.['@format'] }}
</li>
</li>
</ul>
console.log(nodes.length); This won't work because your object
structure is like following :
"Nodes": {
"Node": [
{
"@type": "development",
- - - -
where in **Nodes is an object which has a key as "Node" and this "Node"
key is an array** so console.log(nodes.node.length) should work.
Well, you will have to add the code that you have written for Vue
If you are in a vue app, you can do something like this
<script>
import json from './json/data.json'
export default{
data(){
return{
myJson: json
}
}
}
</script>
and if you are writting it inside an html page. you can do it in 2 steps.
1st is to add the file link as a script
<script src="../file.json"></script>
then in the vue script section you can assign it to the data object.
var ele = new Vue({
el : "#YourElement",
data : ObjName
});
"ObjName" is a name of the json object in the file.
ObjName :
{
"data": [
[
{
"account_id": " "
"account_name": " "
}
You can use a computed property that would reactively take account_name property of the first object of every array:
const data = {
"data": [
[
{
"account_id": "11",
"account_name": "name11"
},
{
"account_id": "12",
"account_name": "name12"
},
{
"account_id": "13",
"account_name": "name13"
},
{
"account_id": "14",
"account_name": "name14"
}
],
[
{
"account_id": "21",
"account_name": "name21"
},
{
"account_id": "22",
"account_name": "name22"
},
{
"account_id": "23",
"account_name": "name23"
}
],
[
{
"account_id": "31",
"account_name": "name31"
},
{
"account_id": "32",
"account_name": "name32"
},
{
"account_id": "33",
"account_name": "name33"
}
]
]
}
new Vue({
el: '#demo',
data() {
return {
data: data.data
}
},
computed: {
firstAccountNames() {
return this.data.map(dataSet => dataSet[0].account_name)
}
}
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="demo">
<ul>
<li v-for="name in firstAccountNames">
{{ name }}
</li>
</ul>
</div>
You need to bind the value to the component as dynamic and not static. So change your blade file to:
@extends('layouts.app')
@section('content')
<!-- see the colon in front of the props, that is a shortcut for v-bind:prop-name -->
<my-profile :user-details="{{ json_encode($userDetails) }}"></my-profile>
@endsection
Otherwise are all values passed to the component as a simple string.
Change this:
<my-profile user-details="{{ json_encode($userDetails) }}"></my-profile>
with this:
<my-profile user-details='@json($userDetails)'></my-profile>
// Pay attention to single quotes instead of double
This worked for me.
» npm install vue-json-pretty
» npm install json-editor-vue
The issue that you currently have is that you are not updating the internData from the transformData function youe should reassign internData with JSON parsed format of same inside the function just like below
transformData() {
this.internData = JSON.parse(this.internData);
}
OR
You could make transformData as a computed property and watch for the type of transformData. Here you can get rid of the click event to parse the data.
new Vue({
el: "#app",
data() {
return {
datatype: "foo",
internData: "[1, 2, 3]",
};
},
methods: {
whatFormat() {
console.log(this.transformData);
console.log(typeof this.transformData);
}
},
computed: {
transformData: function () {
return JSON.parse(this.internData)
}
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
<input v-model="internData" />
<button type="button" @click="whatFormat">what data type</button>
</div>
Your transformData function transforms the string, but the newly created object is not assigned to the internData property.
This should do the trick:
transformData() {
this.internData = JSON.parse(this.internData);
},
use this code:
<div id="vueapp">
<textarea v-model="jsonstr" rows="8" cols="40"></textarea>
<pre>{{ jsonstr | pretty }}</pre>
</div>
and JS:
new Vue({
el: '#vueapp',
data: {
jsonstr: '{"id":1,"name":"A green door","price":12.50,"tags":["home","green"]}'
},
filters: {
pretty: function(value) {
return JSON.stringify(JSON.parse(value), null, 2);
}
}
})
HTML and JS have this built into the language. Try...
<pre>{{ yourObject }}</pre>
This gives the default indent, to specify a custom indent provide it as the third argument to JSON.stringify(...).
// replace 2 with '\t' to do tab indentation
<pre>{{ JSON.stringify(yourObject, null, 2) }}</pre>
If you're outside of Vue then using a combo of JSON.stringify and <pre> will work.