Jump to content
UBot Underground

Recommended Posts

Hi,

 

my json code:

{
	"status": "ok",
	"items": [{
		"subtitle": "Ankara",
		"location": {
			"external_source": "demo",
			"city": "turkey",
			"code": 88589,


		},
		"media_bundles": []
	},
	{
		"subtitle": "Ankara",
		"location": {
			"external_source": "demo",
			"city": "usa",
			"code": 5252525,

		},
		"media_bundles": []
	}
}

city-code

 

turkey-88589

usa-5252525

 

how can ı do upper format? (aymen jsonPath parser or enother plugin ?)

Link to post
Share on other sites

I'd roll this way SaHin,

 

set(#json code,"\{
    \"status\": \"ok\",
    \"items\": [\{
        \"subtitle\": \"Ankara\",
        \"location\": \{
            \"external_source\": \"demo\",
            \"city\": \"turkey\",
            \"code\": 88589,


        \},
        \"media_bundles\": []
    \},
    \{
        \"subtitle\": \"Ankara\",
        \"location\": \{
            \"external_source\": \"demo\",
            \"city\": \"usa\",
            \"code\": 5252525,

        \},
        \"media_bundles\": []
    \}
\}","Global")
clear list(%zipped)
clear list(%cities)
clear list(%codes)
add list to list(%cities,$list from text($find regular expression(#json code,"(?<=\"city\":\\s\").*?(?=\")"),$new line),"Don\'t Delete","Global")
add list to list(%codes,$list from text($find regular expression(#json code,"(?<=\"code\":\\s).*?(?=,)"),$new line),"Don\'t Delete","Global")
loop($list total(%cities)) {
    add item to list(%zipped,"{$next list item(%cities)} -- {$next list item(%codes)}","Don\'t Delete","Global")
}

 

usin the plugin tho should lool like

$..code

 

but not working in U5

regex is more reliable in this case.

CD

  • Like 1
Link to post
Share on other sites

the JSON their is incorrect,it should be

 

var findTown ={
    "status": "ok",
    "items": [{
        "subtitle": "Ankara",
        "location": {
            "external_source": "demo",
            "city": "turkey",
            "code": 88589,


        },
        "media_bundles": []
    },
    {
        "subtitle": "Ankara",
        "location": {
            "external_source": "demo",
            "city": "usa",
            "code": 5252525,

        },
        "media_bundles": []
    }
]
}

 

that is probably why the plugin wasn't working

 

clear list(%towns)
run javascript("var findTown =\{
    \"status\": \"ok\",
    \"items\": [\{
        \"subtitle\": \"Ankara\",
        \"location\": \{
            \"external_source\": \"demo\",
            \"city\": \"turkey\",
            \"code\": 88589,


        \},
        \"media_bundles\": []
    \},
    \{
        \"subtitle\": \"Ankara\",
        \"location\": \{
            \"external_source\": \"demo\",
            \"city\": \"usa\",
            \"code\": 5252525,

        \},
        \"media_bundles\": []
    \}
]
\}")
set(#position,0,"Global")
set(#listCount,$eval("findTown.items.length"),"Global")
loop(#listCount) {
    set(#town,$eval("findTown.items[{#position}].location.city"),"Global")
    set(#code,$eval("findTown.items[{#position}].location.code"),"Global")
    add item to list(%towns,"{#town}-{#code}","Delete","Global")
    increment(#position)
}

  • Like 1
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...