Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1057573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:53:25+00:00 2026-05-16T17:53:25+00:00

I have a complex json array which I want to target a specific line/string

  • 0

I have a complex json array which I want to target a specific line/string and if present then add a small table to web page…

This is the array

{
"coastalWarnings":[{
  "loc":"ABEL",
  "warn":"GALE"
  },{
  "loc":"CASTLEPOINT",
  "warn":"STORM"
  },{
  "loc":"CHALMERS",
  "warn":"GALE"
  },{
  "loc":"CHATHAM ISLANDS",
  "warn":"GALE"
  },{
  "loc":"CONWAY",
  "warn":"STORM"
  },{
  "loc":"COOK",
  "warn":"STORM"
  },{
  "loc":"FOVEAUX",
  "warn":"GALE"
  },{
  "loc":"GREY",
  "warn":"GALE"
  },{
  "loc":"MILFORD",
  "warn":"STORM"
  },{
  "loc":"PORTLAND",
  "warn":"GALE"
  },{
  "loc":"PUYSEGUR",
  "warn":"STORM"
  },{
  "loc":"RAGLAN",
  "warn":"GALE"
  },{
  "loc":"RANGITATA",
  "warn":"GALE"
  },{
  "loc":"STEPHENS",
  "warn":"GALE"
  }
  ],
"isAdvisory":true,
"isOutlook":true,
"isVhf":true,
"isWatch":true,
"liftedWarnings":[
  ],
"oceanicWarnings":[{
  "loc":"FORTIES",
  "warn":"GALE"
  },{
  "loc":"PACIFIC",
  "warn":"GALE"
  },{
  "iceAccretion":true,
  "loc":"SOUTHERN",
  "warn":"GALE"
  },{
  "loc":"SUBTROPIC",
  "warn":"GALE"
  }
  ],
"roadSnowWarnings":[
  ],
"severeWarnings":[{
  "loc":"BULLER",
  "warn":["ISSUE"
    ]
  },{
  "loc":"CANTERBURY",
  "warn":["ISSUE"
    ]
  },{
  "loc":"FIORDLAND",
  "warn":["ISSUE"
    ]
  },{
  "loc":"HAWKES BAY",
  "warn":["ISSUE"
    ]
  },{
  "loc":"MANAWATU",
  "warn":["ISSUE"
    ]
  },{
  "loc":"MARLBOROUGH",
  "warn":["ISSUE"
    ]
  },{
  "loc":"NELSON",
  "warn":["ISSUE"
    ]
  },{
  "loc":"OTAGO",
  "warn":["ISSUE"
    ]
  },{
  "loc":"SOUTHLAND",
  "warn":["ISSUE"
    ]
  },{
  "loc":"TAIHAPE",
  "warn":["ISSUE"
    ]
  },{
  "loc":"TARANAKI",
  "warn":["ISSUE"
    ]
  },{
  "loc":"TAUMARUNUI",
  "warn":["ISSUE"
    ]
  },{
  "loc":"TAUPO",
  "warn":["ISSUE"
    ]
  },{
  "loc":"WAIRARAPA",
  "warn":["ISSUE"
    ]
  },{
  "loc":"WAITOMO",
  "warn":["ISSUE"
    ]
  },{
  "loc":"WANGANUI",
  "warn":["ISSUE"
    ]
  },{
  "loc":"WELLINGTON",
  "warn":["ISSUE"
    ]
  },{
  "loc":"WESTLAND",
  "warn":["ISSUE"
    ]
  }
  ],
"thunderstormWarnings":[
  ]
}

As you can see the array is broken down into parts –

"coastalWarnings"
"liftedWarnings"
"oceanicWarnings"
"roadSnowWarnings"
"severeWarnings"
"thunderstormWarnings"

I wish to target “severeWarnings” and in particular “loc”:”CANTERBURY” which displays as –

  },{
  "loc":"CANTERBURY",
  "warn":["ISSUE"
    ]
  },{

so when present in array it will trigger a table such as

<table align="center" width="100%" bgcolor="red">
     <tr><td><strong>Severe Weather Warning in effect for CANTERBURY</strong></td></tr>
</table>

The biggest problem is the array changes all the time so need to target I guess by searching for specific words or wording unless it can be broken down into parts reliably.

Could something as simple as this work?

<?
$table = <table align="center" width="100%" bgcolor="red"><tr><td><strong>Severe Weather Warning in effect for CANTERBURY</strong></td></tr></table>;

$file = file_get_contents("filename.ext");
if(!strpos($file, ""loc":"CANTERBURY"")) {
echo $table;
}
?

Unsure how to go about this and my php skills are fairly limited so if you would be so kind as to show me a script or a step by step on how to achieve this, I would be ever so appreciative.

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T17:53:26+00:00Added an answer on May 16, 2026 at 5:53 pm

    As Alex suggested, use json_decode

    $s = getData(); // returning the string from the question
    $data = json_decode($s, true);
    
    foreach( $data['severeWarnings'] as $cw ) {
      if ( 'CANTERBURY'===$cw['loc'] ) {
        foreach( $cw['warn'] as $msg ) {
          echo "-- ", $msg, " --\n";
        }
      }
    }
    

    prints -- ISSUE --

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have javascript object which consists of complex array of structures with nested structures
We have a complex json structure which we need to parse in Android. {
I have a complex JSON object that I want represent as C# class. I
I have a complex json written in a string. I know java and a
Suppose you have some complex JSON like: {A : valA, B : { C
I have a method that return a complex JSON object. It's a heavy processing
We have a complex app that serves AJAX JSON streams (using ADO to grab
I have complex GUI application written in Python and wxPython. I want it to
I am using WCF and REST, and I have complex types, which are working
I have some complex regular expressions which I need to comment for readability and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.