Print JSON Object by key in JADE - json

I have a JSON object like this
{
"54634b4ea624675649e91bcd": "2014-12-04T09:21:02.622Z",
"542e7c720fa8e288631a8298": "2014-12-04T09:21:08.672Z",
"542c024f0fa8e288631a8285": "2014-12-19T15:28:27.092Z",
"542beaaf0fa8e288631a8270": "2014-12-19T15:29:22.546Z",
"542e82db0fa8e288631a8299": "2014-12-19T15:31:30.282Z",
"542e83870fa8e288631a829a": "2014-12-19T15:32:22.758Z",
"542e86e50fa8e288631a829c": "2014-12-19T15:33:07.509Z"
}
now i want to print the value of the key 542e7c720fa8e288631a8298 which is 2014-12-04T09:21:08.672Z
How can i print the value of second key in JADE
I have the key 542e7c720fa8e288631a8298 stored in another variable. Any help is much appreciated.

I dont know much about Jade but you may to iterate over the json obj array:
each value, key in obj
h=key
p=value
Then compare your variable(which has key) with 'key'.

Related

How to access the key of a jsoncpp Value

I kind of feel stupid for asking this, but haven't been able to find a way to get the key of a JSON value. I know how to retrieve the key if I have an iterator of the object. I also know of operator[].
In my case the key is not a known value, so can't use get(const char *key) or operator[]. Also can't find a getKey() method.
My JSON looks like this:
{Obj_Array: [{"122":{"Member_Array":["241", "642"]}}]}
For the piece of code to parse {"122":{"Member_Array":["241", "642"]}} I want to use get_key()-like function just to retrieve "122" but seems like I have to use an iterator which to me seems to be overkill.
I might have a fundamental lack of understanding of how jsoncpp is representing a JSON file.
First, what you have won't parse in JsonCPP. Keys must always be enclosed in double quotes:
{"Obj_Array": [{"122":{"Member_Array":["241", "642"]}}]}
Assuming that was just an oversight, if we add whitespace and tag the elements:
{
root-> "Obj_Array" : [
elem0-> {
key0-> "122":
val0-> {
key0.1-> "Member_Array" :
val0.1-> [
elem0.1.0-> "241",
elem0.1.1-> "642" ]
}
}
]
}
Assuming you have managed to read your data into a Json::Value (let's call it root), each of the tagged values can be accessed like this:
elem0 = root[0];
val0 = elem0["122"]
val0_1 = val0["Member_Array"];
elem0_1_0 = val0_1[0];
elem0_1_1 = val0_1[1];
You notice that this only retrieves values; the keys were known a priori. This is not unusual; the keys define the schema of the data; you have to know them to directly access the values.
In your question, you state that this is not an option, because the keys are not known. Applying semantic meaning to unknown keys could be challenging, but you already came to the answer. If you want to get the key values, then you do have to iterate over the elements of the enclosing Json::Value.
So, to get to key0, you need something like this (untested):
elem0_members = elem0.getMemberNames();
key0 = elem0_members[0];
This isn't production quality, by any means, but I hope it points in the right direction.

Fetch JSON data with dashes or hyphens in React

Anyone knows how to solve this problem with react? I need to fetch this data:
<source src={items.preview-hq-mp3.} type="audio/mpeg"></source>
but give error because dashes...error
How to Fetch an object with special characters in the key
You can reference a key with a string and square brackets. This is useful for when you need to get a srance file name or json as part of an object.
In your case I'm not sure if the . at the end is a typo? but this should work either way, so long as it matches the key properly.
<source src={items["preview-hq-mp3."]} type="audio/mpeg"></source>
A bonus use case for this is when you have a variable key name.
const key = "myKey";
const obj = {[key]: 'my value'} // prints out {myKey: 'my value'}

Lua - getting nested table element

i have JSON responce like this:
{"ts":"1026","updates":
[{"type":"message_new","object":{"message":
{"date":1588966108,"from_id":329211115,"id":0,"out":0,"peer_id":2000000003,"text":"test"}}},
{"type":"message_new","object":{"message":
{"date":1588966109,"from_id":329211115,"id":0,"out":0,"peer_id":2000000003,"text":"test2"}}}]}
How to print an "text" field?
I have this responce converted to Lua table.
I tried to call
answer["updates"]["object"]["message"]["text"]
, but i had error 'attempt to index a nil value (field 'object')'
updates is an array. So use
answer["updates"][1]["object"]["message"]["text"]
or
answer.updates[1].object.message.text

Getting value from json by setting key from another json

I need to get value from json by using ng-repeat that inside another json loop.
I had tried as below.
<tr ng:repeat="tableValueElement in tableValueRows">
<td ng:repeat="subHeaderElement in subHeaderColumns" ng-init="map=subHeaderElement.map">{{tableValueElement.map}}</td>
</tr>
tableValueElement = {"name":"Steve","age":24,"street":"RailwayStreet"}
subHeaderElement = {"colspan":2, "map":"name", "color":"grey"}
and I'm trying to get the value ("steve") from "tableValueElement" by setting key ("name") from "subHeaderElement".
So the key is the value of "map" attribute in the "subHeaderElement".
But above method is not returning the value from tableValueElement.
Please help.
You have to use an array notation
{{tableValueElement[map]}}

how to order mysql result based on the json key of a json object stored in a column

jSonColoumn - data type (TEXT)
sample rows
{"scheduledTime":"2014-01-29 19:55:00"}
{"scheduledTime":"2014-01-29 22:55:00"}
{"scheduledTime":"2014-01-29 15:55:00"}
{"scheduledTime":"2014-01-29 08:55:00"}
i need to sort this result with the "scheduledTime" key of the json object stored in the column "jSonColoumn". (Simply i need to order by the result based on the "scheduledTime" key of the json)
Thanks
There are some MySQL JSON functions.
Like this:
select json_extract(columnX, '{"scheduledTime"}')