WinHTTP Send with complex Send parameters - json

I have this input parameter (complex list of inputs) that needs to be sent as part of a HTTP POST request. I have been searching for an AutoIt equivalent to encapsulate the following data, but unsuccessful.
Below given working code is failing with 400 - Bad Request for obvious reason of incomplete input (unable to send ip_list and other array type parameters).
Questions
How to encapsulate the below given data for $oHttp.Send()?
How to encapsulate data types like:
null - aligned_device_template parameter
white-spaced values - description and
empty array - hostname or device_groups
Input parameter in JSON format to be converted & sent in AutoIt
{
"name": "SnmpSIM",
"description": "EM7 device created by BDD test case",
"credentials":"{{feature.credential.body.result_set[*].URI}}",
"organization": "/api/organization/0",
"aligned_device_template": null,
"aligned_collector": "{{feature.appliance_id[0].id[0]}}{{feature.appliance_id[0].id[1]}}",
"discover_non_snmp": "1",
"scan_ports": [
"21",
"22",
"23",
"25",
"80"
],
"ip_lists": [
{
"start_ip": "{{feature.json.ip}}",
"end_ip": "{{feature.json.ip}}"
}
],
"dhcp_enabled": "0",
"duplicate_protection": "1",
"model_device": "1",
"log_all": "1",
"scan_all_ips": null,
"port_scan_timeout": null,
"initial_scan_level": null,
"scan_throttle": null,
"interface_inventory_timeout": "600000",
"max_interface_inventory_count": "10000",
"bypass_interface_inventory": "0",
"hostnames": [],
"device_groups": []
}
Working code
; The data to be sent
$sPD = 'name=SnmpSIM&description=EM7 device created by BDD test case&credentials=37&organization=/api/organization/0&aligned_device_template=null&aligned_collector=1&discover_non_snmp=1&dhcp_enabled=0&duplicate_protection=1&model_device=1&log_all=1&scan_all_ips= null&port_scan_timeout= null&initial_scan_level= null&scan_throttle= null&interface_inventory_timeout=600000&max_interface_inventory_count=10000&bypass_interface_inventory=0&hostnames=&device_groups=&scan_ports=21'
; Creating the object
$oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
$oHTTP.Open("POST", "http://10.2.4.18/api/discovery_session", False)
$oHTTP.SetCredentials("username","password",0)
$oHTTP.SetRequestHeader("Content-Type", "application/em7-resource-uri")
; Performing the Request
$oHTTP.Send($sPD)
; Download the body response if any, and get the server status response code.
$oReceived = $oHTTP.ResponseText
$oStatusCode = $oHTTP.Status
If $oStatusCode <> 200 then
MsgBox(4096, "Response code", $oStatusCode)
EndIf
; Saves the body response regardless of the Response code
$file = FileOpen("Received.html", 2) ; The value of 2 overwrites the file if it already exists
FileWrite($file, $oReceived)
FileClose($file)
Sample VBA code for reference
Dim Items As New Collection
Dim Item As Dictionary
Dim Id As Long
For Id = 1 To 2
Set Item = New Dictionary
Item("iditem") = Id
Item("amount") = 1
Items.Add Item
Next Id
Request.AddBodyParameter "id", 5633
Request.AddBodyParameter "items", Items
$oDictionary = ObjCreate("Scripting.Dictionary")
$oDictionary.ADD("start_ip", "10.20.7.31")
$oDictionary.ADD("end_ip", "10.20.7.33")

Related

How to access field in list of JSON objects in a django SerializerMethodField?

I am creating an API for a game where users get points for labelling images. If a user has labeled an image with the same label as another, the score gets updated by 5 points (and 25 if that player is their opponent). I have declared the field score inside my serializer as a SerializerMethodField.
In the get_score method, I am trying to access the tag__name field inside the list of tags_to_compare and simply extract the strings and store them in a list.
I have tried the following inside my serializer:
Update
I have updated my get_score method as follows:
serializers.py
score = serializers.SerializerMethodField('get_score')
...
def get_score(self, tagging):
score = 0
resource_id = tagging.resource.id
# A previously played gameround for this resource is coordinated for Tag verification
coordinated_gameround = Gameround.objects.all().filter(taggings__resource_id=resource_id).order_by("?").first()
# list of tag_name from coordinated gameround
coordinated_gameround_tags = coordinated_gameround.taggings.all().values_list("tag__name", flat=True)
if Tag.objects.all().filter(name=tagging) in coordinated_gameround_tags:
score += 25
return score
I tested the following line and it retrieves a list of taggings.
coordinated_gameround_tags = coordinated_gameround.taggings.all().values_list("tag__name", flat=True)
This is the JSON Object where the list of tags is:
{
"gameround": {
"id": 2014305513,
"user": {
"id": 1,
"username": "carina",
"is_superuser": true
},
"score": 50,
"tags_to_compare": [
{
"tag_id": 153,
"tag__name": "night",
"tag__language": "en",
"resource_id": 323570
},
{
"tag_id": 10437,
"tag__name": "dress",
"tag__language": "en",
"resource_id": 323570
},
{
"tag_id": 9598,
"tag__name": "sleep",
"tag__language": "en",
"resource_id": 323570
}
]
}
}
coordinated_gameround is a Gameround instance of your model. Not a Dict. So you cannot access it with coordinated_gameround[key].
If your Gameround has a field named "name" or "langage", you can get those values with
name = coordinated_gameround.name
langage = coordinated_gameround.langage
Also, there might be an error with this line
Tag.objects.all().filter(name=tagging) in coordinated_gameround_tags
Do you expect coordinated_gameround_tags to contain a list of queryset ?

how to extract properly when sqlite json has value as an array

I have a sqlite database and in one of the fields I have stored complete json object . I have to make some json select requests . If you see my json
the ALL key has value which is an array . We need to extract some data like all comments where "pod" field is fb . How to extract properly when sqlite json has value as an array ?
select json_extract(data,'$."json"') from datatable ; gives me entire thing . Then I do
select json_extract(data,'$."json"[0]') but i dont want to do it manually . i want to iterate .
kindly suggest some source where i can study and work on it .
MY JSON
{
"ALL": [{
"comments": "your site is awesome",
"pod": "passcode",
"originalDirectory": "case1"
},
{
"comments": "your channel is good",
"data": ["youTube"],
"pod": "library"
},
{
"comments": "you like everything",
"data": ["facebook"],
"pod": "fb"
},
{
"data": ["twitter"],
"pod": "tw",
"ALL": [{
"data": [{
"codeLevel": "3"
}],
"pod": "mo",
"pod2": "p"
}]
}
]
}
create table datatable ( path string , data json1 );
insert into datatable values("1" , json('<abovejson in a single line>'));
Simple List
Where your JSON represents a "simple" list of comments, you want something like:
select key, value
from datatable, json_each( datatable.data, '$.ALL' )
where json_extract( value, '$.pod' ) = 'fb' ;
which, using your sample data, returns:
2|{"comments":"you like everything","data":["facebook"],"pod":"fb"}
The use of json_each() returns a row for every element of the input JSON (datatable.data), starting at the path $.ALL (where $ is the top-level, and ALL is the name of your array: the path can be omitted if the top-level of the JSON object is required). In your case, this returns one row for each comment entry.
The fields of this row are documented at 4.13. The json_each() and json_tree() table-valued functions in the SQLite documentation: the two we're interested in are key (very roughly, the "row number") and value (the JSON for the current element). The latter will contain elements called comment and pod, etc..
Because we are only interested in elements where pod is equal to fb, we add a where clause, using json_extract() to get at pod (where $.pod is relative to value returned by the json_each function).
Nested List
If your JSON contains nested elements (something I didn't notice at first), then you need to use the json_tree() function instead of json_each(). Whereas the latter will only iterate over the immediate children of the node specified, json_tree() will descend recursively through all children from the node specified.
To give us some data to work with, I have augmented your test data with an extra element:
create table datatable ( path string , data json1 );
insert into datatable values("1" , json('
{
"ALL": [{
"comments": "your site is awesome",
"pod": "passcode",
"originalDirectory": "case1"
},
{
"comments": "your channel is good",
"data": ["youTube"],
"pod": "library"
},
{
"comments": "you like everything",
"data": ["facebook"],
"pod": "fb"
},
{
"data": ["twitter"],
"pod": "tw",
"ALL": [{
"data": [{
"codeLevel": "3"
}],
"pod": "mo",
"pod2": "p"
},
{
"comments": "inserted by TripeHound",
"data": ["facebook"],
"pod": "fb"
}]
}
]
}
'));
If we were to simply switch to using json_each(), then we see that a simple query (with no where clause) will return all elements of the source JSON:
select key, value
from datatable, json_tree( datatable.data, '$.ALL' ) limit 10 ;
ALL|[{"comments":"your site is awesome","pod":"passcode","originalDirectory":"case1"},{"comments":"your channel is good","data":["youTube"],"pod":"library"},{"comments":"you like everything","data":["facebook"],"pod":"fb"},{"data":["twitter"],"pod":"tw","ALL":[{"data":[{"codeLevel":"3"}],"pod":"mo","pod2":"p"},{"comments":"inserted by TripeHound","data":["facebook"],"pod":"fb"}]}]
0|{"comments":"your site is awesome","pod":"passcode","originalDirectory":"case1"}
comments|your site is awesome
pod|passcode
originalDirectory|case1
1|{"comments":"your channel is good","data":["youTube"],"pod":"library"}
comments|your channel is good
data|["youTube"]
0|youTube
pod|library
Because JSON objects are mixed in with simple values, we can no longer simply add where json_extract( value, '$.pod' ) = 'fb' because this produces errors when value does not represent an object. The simplest way around this is to look at the type values returned by json_each()/json_tree(): these will be the string object if the row represents a JSON object (see above documentation for other values).
Adding this to the where clause (and relying on "short-circuit evaluation" to prevent json_extract() being called on non-object rows), we get:
select key, value
from datatable, json_tree( datatable.data, '$.ALL' )
where type = 'object'
and json_extract( value, '$.pod' ) = 'fb' ;
which returns:
2|{"comments":"you like everything","data":["facebook"],"pod":"fb"}
1|{"comments":"inserted by TripeHound","data":["facebook"],"pod":"fb"}
If desired, we could use json_extract() to break apart the returned objects:
.mode column
.headers on
.width 30 15 5
select json_extract( value, '$.comments' ) as Comments,
json_extract( value, '$.data' ) as Data,
json_extract( value, '$.pod' ) as POD
from datatable, json_tree( datatable.data, '$.ALL' )
where type = 'object'
and json_extract( value, '$.pod' ) = 'fb' ;
Comments Data POD
------------------------------ --------------- -----
you like everything ["facebook"] fb
inserted by TripeHound ["facebook"] fb
Note: If your structure contained other objects, of different formats, it may not be sufficient to simply select for type = 'object': you may have to devise a more subtle filtering process.

how to extract elements in json string in vba

I have the following json string:
[
{
"Features": {
"Level": [
{
"endDate": "2018-12-11",
"minimum": "0.000000000000",
"maximum": "0.000000000000",
"value": "228.108000000000",
"payDate": "0"
},
{
"endDate": "2018-12-11",
"minimum": "0.000000000000",
"maximum": "0.000000000000",
"value": "3143.513000000000",
"payDate": "0"
}
]
}
},
]
I was trying to extract the two values in excel using vba and have the following code (where result2 would be the json string)
Public Sub GetS (result2 As String, m As Integer)
Dim activeWS As Worksheet
Set activeWS = ThisWorkbook.Worksheets("Data")
Dim jsonStr As String, json As Object, headers()
jsonStr = result2
Set json = JsonConverter.ParseJson(jsonStr)(1)
activeWS.Cells(m, 19) = json("Features")("Level")(0)("value")
activeWS.Cells(m, 20) = json("Features")("Level")(1)("value")
End Sub
the second part of the vba works, where it grab the value of 3143.51 (the second number), i'm wondering how can I get the first value (228.10).
I've tried using ("Initial Level")(0)("value") but it doesn't work.
Thank you so much.
JSON arrays get converted to VBA Collections - these are indexed from 1 not from zero
Try this:
jsonStr = Range("I10").Value 'your json sample
Set json = JsonConverter.ParseJson(jsonStr)(1)
Debug.Print json("Features")("Level")(1)("value") '>>228.108000000000
Debug.Print json("Features")("Level")(2)("value") '>>3143.513000000000
(tested and confirmed)
Here is how to access data in the JSON string:
Json("match")("awayTeam")("coach")("countryOfBirth")
Json("match")("awayTeam")("coach")("nationality")
Json("match")("awayTeam")("captain")("id")
Json("match")("awayTeam")("captain")("name")
Json("match")("awayTeam")("captain")("shirtNumber")
Json("match")("awayTeam")("lineup")(1)("id")
Json("match")("awayTeam")("lineup")(1)("name")
Json("match")("awayTeam")("lineup")(1)("position")
Json("match")("awayTeam")("lineup")(1)("shirtNumber")
Json("match")("awayTeam")("lineup")(2)("id")
Json("match")("awayTeam")("lineup")(2)("name")
Json("match")("awayTeam")("lineup")(2)("position")
Json("match")("awayTeam")("lineup")(2)("shirtNumber")
Json("match")("awayTeam")("lineup")(3)("id")
Json("match")("awayTeam")("lineup")(3)("name")
Json("match")("awayTeam")("lineup")(3)("position")
Json("match")("awayTeam")("lineup")(3)("shirtNumber")
Json("match")("awayTeam")("lineup")(4)("id")
Json("match")("awayTeam")("lineup")(4)("name")
Json("match")("awayTeam")("lineup")(4)("position")
Json("match")("awayTeam")("lineup")(4)("shirtNumber")
Json("match")("awayTeam")("lineup")(5)("id")
Json("match")("awayTeam")("lineup")(5)("name")
Json("match")("awayTeam")("lineup")(5)("position")
Json("match")("awayTeam")("lineup")(5)("shirtNumber")
Json("match")("awayTeam")("lineup")(6)("id")
Json("match")("awayTeam")("lineup")(6)("name")
Json("match")("awayTeam")("lineup")(6)("position")
Json("match")("awayTeam")("lineup")(6)("shirtNumber")
Json("match")("awayTeam")("lineup")(7)("id")
Json("match")("awayTeam")("lineup")(7)("name")
Json("match")("awayTeam")("lineup")(7)("position")
Json("match")("awayTeam")("lineup")(7)("shirtNumber")
Json("match")("awayTeam")("lineup")(8)("id")
Json("match")("awayTeam")("lineup")(8)("name")
Json("match")("awayTeam")("lineup")(8)("position")
Json("match")("awayTeam")("lineup")(8)("shirtNumber")
Json("match")("awayTeam")("lineup")(9)("id")
Json("match")("awayTeam")("lineup")(9)("name")
Json("match")("awayTeam")("lineup")(9)("position")
Json("match")("awayTeam")("lineup")(9)("shirtNumber")
Json("match")("awayTeam")("lineup")(10)("id")
Json("match")("awayTeam")("lineup")(10)("name")
Json("match")("awayTeam")("lineup")(10)("position")
Json("match")("awayTeam")("lineup")(10)("shirtNumber")
Json("match")("awayTeam")("lineup")(11)("id")
Json("match")("awayTeam")("lineup")(11)("name")
Json("match")("awayTeam")("lineup")(11)("position")
Json("match")("awayTeam")("lineup")(11)("shirtNumber")
Json("match")("awayTeam")("bench")(1)("id")
Json("match")("awayTeam")("bench")(1)("name")
Json("match")("awayTeam")("bench")(1)("position")
Json("match")("awayTeam")("bench")(1)("shirtNumber")
Json("match")("awayTeam")("bench")(2)("id")
Json("match")("awayTeam")("bench")(2)("name")
Json("match")("awayTeam")("bench")(2)("position")
Json("match")("awayTeam")("bench")(2)("shirtNumber")
Json("match")("awayTeam")("bench")(3)("id")
Json("match")("awayTeam")("bench")(3)("name")
Json("match")("awayTeam")("bench")(3)("position")
Json("match")("awayTeam")("bench")(3)("shirtNumber")
Json("match")("awayTeam")("bench")(4)("id")
Json("match")("awayTeam")("bench")(4)("name")
Json("match")("awayTeam")("bench")(4)("position")
Json("match")("awayTeam")("bench")(4)("shirtNumber")
Json("match")("awayTeam")("bench")(5)("id")
Json("match")("awayTeam")("bench")(5)("name")
Json("match")("awayTeam")("bench")(5)("position")
Json("match")("awayTeam")("bench")(5)("shirtNumber")
Json("match")("awayTeam")("bench")(6)("id")
Json("match")("awayTeam")("bench")(6)("name")
Json("match")("awayTeam")("bench")(6)("position")
Json("match")("awayTeam")("bench")(6)("shirtNumber")
Json("match")("awayTeam")("bench")(7)("id")
Json("match")("awayTeam")("bench")(7)("name")
Json("match")("awayTeam")("bench")(7)("position")
Json("match")("awayTeam")("bench")(7)("shirtNumber")
Json("match")("goals")(1)("minute")
Json("match")("goals")(1)("extraTime")
Json("match")("goals")(1)("type")
Json("match")("goals")(1)("team")("id")
Json("match")("goals")(1)("team")("name")
Json("match")("goals")(1)("scorer")("id")
Json("match")("goals")(1)("scorer")("name")
Json("match")("goals")(1)("assist")("id")
Json("match")("goals")(1)("assist")("name")
Json("match")("goals")(2)("minute")
Json("match")("goals")(2)("extraTime")
Json("match")("goals")(2)("type")
Json("match")("goals")(2)("team")("id")
Json("match")("goals")(2)("team")("name")
Json("match")("goals")(2)("scorer")("id")
Json("match")("goals")(2)("scorer")("name")
Json("match")("goals")(2)("assist")("id")
Json("match")("goals")(2)("assist")("name")
Json("match")("goals")(3)("minute")
Json("match")("goals")(3)("extraTime")
Json("match")("goals")(3)("type")
Json("match")("goals")(3)("team")("id")
Json("match")("goals")(3)("team")("name")
Json("match")("goals")(3)("scorer")("id")
Json("match")("goals")(3)("scorer")("name")
Json("match")("goals")(3)("assist")
Json("match")("bookings")(1)("minute")
Json("match")("bookings")(1)("team")("id")
Json("match")("bookings")(1)("team")("name")
Json("match")("bookings")(1)("player")("id")
Json("match")("bookings")(1)("player")("name")
Json("match")("bookings")(1)("card")
Json("match")("bookings")(2)("minute")
Json("match")("bookings")(2)("team")("id")
Json("match")("bookings")(2)("team")("name")
Json("match")("bookings")(2)("player")("id")
Json("match")("bookings")(2)("player")("name")
Json("match")("bookings")(2)("card")
Json("match")("bookings")(3)("minute")
Json("match")("bookings")(3)("team")("id")
Json("match")("bookings")(3)("team")("name")
Json("match")("bookings")(3)("player")("id")
Json("match")("bookings")(3)("player")("name")
Json("match")("bookings")(3)("card")
Json("match")("bookings")(4)("minute")
Json("match")("bookings")(4)("team")("id")
Json("match")("bookings")(4)("team")("name")
Json("match")("bookings")(4)("player")("id")
Json("match")("bookings")(4)("player")("name")
Json("match")("bookings")(4)("card")
Json("match")("bookings")(5)("minute")
Json("match")("bookings")(5)("team")("id")
Json("match")("bookings")(5)("team")("name")
Json("match")("bookings")(5)("player")("id")
Json("match")("bookings")(5)("player")("name")
Json("match")("bookings")(5)("card")
Json("match")("bookings")(6)("minute")
Json("match")("bookings")(6)("team")("id")
Json("match")("bookings")(6)("team")("name")
Json("match")("bookings")(6)("player")("id")
Json("match")("bookings")(6)("player")("name")
Json("match")("bookings")(6)("card")
Json("match")("bookings")(7)("minute")
Json("match")("bookings")(7)("team")("id")
Json("match")("bookings")(7)("team")("name")
Json("match")("bookings")(7)("player")("id")
Json("match")("bookings")(7)("player")("name")
Json("match")("bookings")(7)("card")
Json("match")("substitutions")(1)("minute")
Json("match")("substitutions")(1)("team")("id")
Json("match")("substitutions")(1)("team")("name")
Json("match")("substitutions")(1)("playerOut")("id")
Json("match")("substitutions")(1)("playerOut")("name")
Json("match")("substitutions")(1)("playerIn")("id")
Json("match")("substitutions")(1)("playerIn")("name")
Json("match")("substitutions")(2)("minute")
Json("match")("substitutions")(2)("team")("id")
Json("match")("substitutions")(2)("team")("name")
Json("match")("substitutions")(2)("playerOut")("id")
Json("match")("substitutions")(2)("playerOut")("name")
Json("match")("substitutions")(2)("playerIn")("id")
Json("match")("substitutions")(2)("playerIn")("name")
Json("match")("substitutions")(3)("minute")
Json("match")("substitutions")(3)("team")("id")
Json("match")("substitutions")(3)("team")("name")
Json("match")("substitutions")(3)("playerOut")("id")
Json("match")("substitutions")(3)("playerOut")("name")
Json("match")("substitutions")(3)("playerIn")("id")
Json("match")("substitutions")(3)("playerIn")("name")
Json("match")("substitutions")(4)("minute")
Json("match")("substitutions")(4)("team")("id")
Json("match")("substitutions")(4)("team")("name")
Json("match")("substitutions")(4)("playerOut")("id")
Json("match")("substitutions")(4)("playerOut")("name")
Json("match")("substitutions")(4)("playerIn")("id")
Json("match")("substitutions")(4)("playerIn")("name")
Json("match")("substitutions")(5)("minute")
Json("match")("substitutions")(5)("team")("id")
Json("match")("substitutions")(5)("team")("name")
Json("match")("substitutions")(5)("playerOut")("id")
Json("match")("substitutions")(5)("playerOut")("name")
Json("match")("substitutions")(5)("playerIn")("id")
Json("match")("substitutions")(5)("playerIn")("name")
Json("match")("substitutions")(6)("minute")
Json("match")("substitutions")(6)("team")("id")
Json("match")("substitutions")(6)("team")("name")
Json("match")("substitutions")(6)("playerOut")("id")
Json("match")("substitutions")(6)("playerOut")("name")
Json("match")("substitutions")(6)("playerIn")("id")
Json("match")("substitutions")(6)("playerIn")("name")
Json("match")("referees")(1)("id")
Json("match")("referees")(1)("name")
Json("match")("referees")(1)("nationality")
Json("match")("referees")(2)("id")
Json("match")("referees")(2)("name")
Json("match")("referees")(2)("nationality")
Json("match")("referees")(3)("id")
Json("match")("referees")(3)("name")
Json("match")("referees")(3)("nationality")
Json("match")("referees")(4)("id")
Json("match")("referees")(4)("name")
Json("match")("referees")(4)("nationality")
The two answers below show how to use a function that I wrote, PrintJSONAccessors(), to unravel the collections and arrays produced by JsonConverter.ParseJson().
Using VBA and VBA-JSON to access JSON data from Wordpress API
How to get, JSON values to Work in VBA-JSON

R - Create JSON for Adobe Analytics API call - define object conditionally

I have following code to create a JSON for making a call to Adobe Analytics API (method segment.save)
item <-
list(definition = list(
container = list (
type = "hits",
operator = "or",
rules=I(list(
list(value= "test1 test2",
operator = "contains_any",
element = "page")))
)
),
owner="test",
reportSuiteID="test",
description="API Generated Segment",
name="test segment"
)
Once prettyfied and auto-unboxed, the result is:
> jsonlite::toJSON(item, pretty = T, auto_unbox= T)
{
"definition": {
"container": {
"type": "hits",
"operator": "or",
"rules": [
{
"value": "test1 test2",
"operator": "contains_any",
"element": "page"
}
]
}
},
"owner": "test",
"reportSuiteID": "test",
"description": "API Generated Segment",
"name": "test segment"
}
Good for creating new segments, but not so good for editing them
The JSON structure is valid, as I am able to create the new segment. However, I would like to check if the segment already exists (using f.i. the GetSegments() function from randyzwitch RSiteCatalyst package and check if name coincides already with a created segment). If the segment already exists, I want to pass the id to the API call, which is the method used for editing already existing segments. It should then look like:
> jsonlite::toJSON(item, pretty = T, auto_unbox= T)
{
"definition": {
...
},
"owner": "test",
"reportSuiteID": "test",
"description": "API Generated Segment",
"name": "test segment",
"id": "s1982XXXXXXXXX_XXXXX_XXXXX",
}
It is possible to make an if alike statement within the list() definition provided in the first piece of code? I would like to reach a solution that does not need an if statement that checks if segmentID exists and, depending on it, generates a call with id or a call without id.
Once a "JSON alike structure" is created using list function:
item <-
list(definition = list(
container = list (
type = "hits",
operator = "or",
rules=I(list(
list(value= "test1 test2",
operator = "contains_any",
element = "page")))
)
),
owner="test",
reportSuiteID="test",
description="API Generated Segment",
name="test segment"
)
We can push new elements to this list using the needed conditions. For example, if we have our segment IDs in a dataframe with name segments, we can push this ID to item this way:
if (!is.na(segments$segmentID[i])) {
item <- c(item, id=segments$segmentID[i])
}

simple json parsing with asp Xtreme

Just confused with one little thing.
I am currently getting { "data": [ { "response": "true" } ] } with the following code.
But I simple want to get { "response": "true" }.
I tried every way I can but I kept failing.
I will appreciate a lot if you can help me with it.
Set Dataset = JSON.parse("{ ""data"": [] }")
Set Record = JSON.parse("{}")
Record.set "response", "true"
Dataset.data.push(Record)
Set Record = nothing
Data = JSON.stringify(Dataset, null, 2)
Set Record = JSON.parse("{}")
Record.set "response", "true"
Data = JSON.stringify(Record, null, 2)
I assume that JSONObject.data.push adds the record to an unnamed array.