Php Key Value Pair

1 view
Skip to first unread message

Lorin Searing

unread,
Aug 4, 2024, 5:02:14 PM8/4/24
to provsoftbanud
Destinationsaccept key-value data in standard or serialized format. Standard formatting organizes data into separate key-value pairs. Each key is stated explicitly, even when used again to define a different value. By contrast, serialized formatting condenses multiple values into one set defined by a single key. Also, in a serialized pair, a special indicator is used to separate the values within the key-value set. Finally, standard and serialized key-values can contain single or multiple values. The following table provides examples of standard and serial key-value formats.

What I am confused about is how this is different from a normal variable. Say a variable of type String points to an object or int variable points to int value. Isn't that variable a "key", and the object a "value?


However, it is more common to talk about key-value pairs in the context of a mapping, i.e. a (mathematical) function which maps from a key to the corresponding value or values. Depending on the properties of this mapping, you may constrain the set of key-value pairs. For example, for a 1-to-1 mapping, you need the keys in the set to be unique.


Well ... an array could be considered as a mapping from a set of indexes (integers) to values. But a mapping is more general. And in Java, arrays have other properties that distinguish them from Maps ... and they have a much simpler, faster, and less memory-hungry implementation.


No. A key can be any type. (It is generally a bad idea to use a mutable type as a key, especially if your mapping is implemented using one of the standard Map types in Java. However, even that can work in some circumstances.)


No. Or at least, not in a static language like Java. The thing that distinguishes a key-value pair from a variable binding is that the "key" object is data, and hence can take different values. By contrast, a variable's name is hard-wired in the source code of your program: you can't change it at runtime.


(In some dynamic languages, you can create new variables dynamically (at runtime), and for such languages you could argue that variables are key-value pairs in a mapping that represents the scope ... at some point in the program's execution. But Java isn't like that ...)


A key-value pair is two values usually connected in such a way that the value is accessed using the key. They are commonly used in various data-structures to provide fast access to values. Check out hashtable data structure for instance (in Java, you can take a look at HashMap or Hashtable)


Generally speaking DPLs are not so good for dynamic data, but even then it's not hard. You can't use the arrow syntax because it will assume that the property is called the literal symbol name on the right hand side of the arrow - it can't be a variable.


That list '("a" "b" "c") is not really a disembodied property list. A disembodied property list is a plain SKILL list with the first element potentially being anything (often nil) followed by alternating key/value pairs. And the keys (or slots or whatever you wanna call them...) need to be symbols which is not the case in your example. The underlying function of the arrow operator (->) is getq(..), so dpl->name is under the hood just

(getq dpl name)

However as I said that requires the keys to be symbols! Or is there any good reason why you would want the slot names to be strings?


It would be prohibitively expensive to continuously check the list that it consists of symbol-value pairs only. Also, because a DPL is just a list that is interpreted specially, there's nothing to stop you hiding other information in the list which will be ignored by the DPL operator ->, so producing a warning would break existing code. Since using dpl1->key returns nil if key doesn't exist, that's the case here and so everything is as expected...


Then from this perspective, it is understandable and applicable. Be little bit pedantic and off-topic, SKILL language itself always give me prosmiscuous feeling. I just guess, maybe it firstly originated from LISP and late absorbed some traits from other languages. In fact key-value pair is a strong binding in data structure. But in DPL, this binding is easily be challenged by normal list element operation like nth etc. That makes makeTable more appealing. Except DPL, a symbol also has property list which can be accessed by dot(.) operator but it seems this data structure is not heavily used in the practice.


Disembodied property lists are a long-standing simple way of representing structured data in lists, one of the primitive datatypes in SKILL. They are not intended for general purpose key-value pairs - the only keys that are supported are symbols. If you need a data structure that can handle other object types as keys, then you can use hash tables (which have been in SKILL for over 25 years, so are not exactly new). DPLs are not really so good for arbitrary keys - they're mostly for objects with a small number of keys.


Property lists on symbols are used for some operations, but because they are tied to the symbol containing them, they are mostly used for settings where you don't have a variable number of objects. I use them from time to time to represent persistent state (although a better way is to use SKILL++ lexical scoping and the closures that offers).


I don't think you can use DELIMS to do this because as you've noted it doesn't work well when one of your delimiters shows up in a key or value field. I had to solve this by using a REGEX instead, see: -base.splunk.com/answers/34550/help-with-regex-to-separate-keyvalue-pairs-with-a-charac...


However, I cannot get the Name, ID, and City into columns because there is nothing to tell me what student, ID, and city are associated with each other, unless I just assume it is in sequential order, in which case I can get this:


Here is a different approach in the query editor. As @edhans suggested, it depends on the consistency of your data. If the values are all sequential and there is a repeating pattern of 7 values, this should work for you to get the result shown below.


@KiranGupta15 - Not sure, doesn't look fun at all. What is the expected result of that? This is something that you likely want to do in Power Query. @ImkeF , @edhans do you have any magic for this poor soul?


Hi Greg, I too have the same situaton where i have a column in excel which is a output of a powershell script which has lot of comma separated values. I need to get the workspace name. Here one important thing to note, i dont have same set of key value pairs in all the columns, Could you suggest how to extract only one key value pair using power bi.


Using the Splunk addon for AWS to collect ec2 instance metadata I get an array called tags with key/value pairs such as below. What I want to do is extract the cluster name as a distinct var so that I can search on it or even better aggregate on it. Thoughts?


A little linguistics here. In JSON, square brackets [] denote an array of JSON object, whereas curly brackets denote a list of key-value pairs. A JSON object can be an array or a list of key-value pairs; a JSON value can also be an array or a list of key-value pairs.


Splunk doesn't have a nested notation. So, SPL flattens JSON paths by concatenating various JSON keys with dots (".") and curly brackets ("") to form Splunk field names. Significantly, the string "" in SPL signifies an array; in JSON, that means that the value of the key preceding "" is enclosed by [].


In your text posting of sample data, the entire event is enclosed by []. That is why I asked if Splunk gives fields like .Resource.InstanceDetails.Tags.Key, i.e., every field name is preceded by "". (This is extremely rare in real life.) If Splunk gives you fields like detail.resource.instanceDetails.tags.key, that means that the events are not enclosed by [], but more like


If this is the case, the original code should work, except you need to make letter cases match what Splunk shows. (SPL's case tolerance can be lax in some commands, but generally, field names are always case sensitive.)


There have been several recent discussions similar to this, like How to Extract JSON format as fields? and How to extract JSON with key name specified as a key. My goto method is spath. Once multivalued tags subfields are extracted, you can use mvfind to find "cluster"s index, and mvindex to extract cluster's name.


Hello i am at a loss here. I have a webhook that posts the body below shown below. I am trying to get the Id/values of the "Questions" object array. The issue is its a dynamic array. Normally i would just do a string variable and do an expression of something like a parse of questions and then on the variable i would do output('Parse')?[0]?['Value']. But not all the questions in the questions object array are sent every time. Plus the order is dynamic. Any idea how i can select a questions object by Id name vs by the numbered order? Thanks for your time.


You could use a select action and repurpose the id as a key with a label and value postfix. This will return a nested array but as the key value pairs should be unique at this point you can unnest them.


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Cheers,

Damien



P.S. take a look at my new blog here and like & subscribe to my YouTube Channel thanks ?


Another option is a query that can create a key/value variable. The query should return two columns that are named __text and __value. The __text column value should be unique (if it is not unique then the first value is used). The options in the dropdown will have a text and value that allow you to have a friendly name as text and an id as the value.

3a8082e126
Reply all
Reply to author
Forward
0 new messages