Deciphering unconventional JSON formats

Can anyone identify the format of this JSON (if it even is JSON!) from the code snippet below? I've extracted this data from a website's HTML and now I'm struggling to parse it in C# using a JSON parser. The data requires significant preprocessing to align with 'valid' JSON standards as per JSONLint. One issue is that variable names should be wrapped in double quotes, unlike the current structure.

{
"status": "A",
"displayed": "Y",
"start_time": "2010-11-26 00:00:00",
"start_time_xls": {
    "en": "26thofNov2010 00:00am",
    "es": "26Nov2010 00:00am"
},
"suspend_at": "2010-11-26 19:57:59",
"is_off": "Y",
"score_home": "",
"score_away": "",
"bids_status": "",
"period_id": "",
"curr_period_start_time": "",
"score_extra_info": "",
"ev_id": 2257335,
"blurb": "",
"last_mkts_of_day": false,
"follow_hcap_mkt": 10999896
}

This data will always maintain the same structure, making it ideal for direct parsing into an object in languages like C# or Java.

Answer โ„–1

Utilize the powerful Json.Net library to effectively parse your input string. You can also explore using the dynamic feature with the assistance of this custom extension class (successfully tested with your specific string).

dynamic jsonObject = JsonUtils.JsonObject.GetDynamicJsonObject(inputString);
Console.WriteLine(jsonObject.names.en);
Console.WriteLine(jsonObject.status);
Console.WriteLine(jsonObject.start_time_xls.en);
Console.WriteLine(jsonObject.suspend_at);

You can achieve the same results using pure Json.Net as well.

JObject json =  (JObject)JsonConvert.DeserializeObject(jsonData);
Console.WriteLine(json["names"]["en"]);
Console.WriteLine(json["status"]);
Console.WriteLine(json["start_time_xls"]["en"]);
Console.WriteLine(json["suspend_at"]);

Answer โ„–2

When working with JSON, it is important to ensure that all names are enclosed in double quotes, as this is a requirement for valid JSON syntax. The code provided seems to be a valid JavaScript object instead. For more information on JSON formatting, you can refer to the official JSON website: http://json.org/

If you intend to convert the object to JSON within a JavaScript environment, you can utilize the window.JSON.stringify method for the conversion process.

To see a demonstration of this process in action, feel free to check out the following demo link: http://jsfiddle.net/ThinkingStiff/3xZD8/

var object = {
    names: {
        en: 'VirtualMarket-2MinuteLevel',
        es: 'VirtualMarket-2MinuteLevel'
    },
    status: 'A',
    displayed: 'Y',
    start_time: '2010-11-2600: 00: 00',
    start_time_xls: {
        en: '26thofNov201000: 00am',
        es: '26Nov201000: 00am'
    },
    suspend_at: '2010-11-2619: 57: 59',
    is_off: 'Y',
    score_home: '',
    score_away: '',
    bids_status: '',
    period_id: '',
    curr_period_start_time: '',
    score_extra_info: '',
    ev_id: 2257335,
    blurb: '',
    last_mkts_of_day: false,
    follow_hcap_mkt: 10999896
    },
    json = window.JSON.stringify( object );

Answer โ„–3

Regarding its validity (my vote is no):

  • Input the string;
  • regex {^\s*([a-z0-9_]+)\:} {"\1":} g

This method appears to be effective for this specific dataset, and I suspect they are simply concatenating the output, making it safe for now.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Crafting a Customized Form with JSON using Kendo-UI

I have successfully created a dynamic form using JSON and Kendo.Observable. However, I am facing issues with initializing the dropdownlist values within the same JSON object. The only workaround I found is to bind the dropdown lists to a separate JSON requ ...

Tips for displaying HTML5 validation messages when the input is changed

I am working on a form where I prefer not to submit it directly, as I am making an AJAX call instead. However, I still want the HTML5 validation messages to show up when an input field is left empty. I have managed to display the validation message when a ...

Integration of Angular.js functionalities within a Node.js application

After working on my node.js app for a few weeks, I decided to add some additional features like infinite-scroll. To implement this, I needed to use packages in node.js along with angular.js. So, I decided to introduce angular.js support to the app, specifi ...

When working with Next.js Components, be aware that using a return statement in a forbidden context can lead to

Whenever I try to add a new component to my Next.js project, I encounter an error that displays the following: `./components/GridMember.js Error: error: Return statement is not allowed here | 6 | return (test); | ^^^^^^^^^^^^^^^^^^^^^^^^^ Caused ...

Retrieve the id of the anchor tag that was selected upon clicking, and then dynamically change the content of another div

Seeking guidance on how to dynamically change the content of a div element based on which anchor tag is clicked. Below is the HTML structure and JavaScript function I have attempted: HTML: <div> <a id="a1" href="javascript: changeDiv();">tag1 ...

Java - Generating a collection of dates

I am facing a challenge with a problem I'm working on. I need to develop a banking system that keeps track of both incoming and outgoing expenses. Currently, I have set up an Array of objects to store the Name, amount, and frequency in weeks (e.g. 4) ...

Caution: Prop type validation failed due to an invalid value being passed to ForwardRef(Slider)

Currently, I'm in the process of building a Material UI range Slider with two values. It functions correctly if initialized like this: const [value, setValue] = React.useState([5,20]); const [value, setValue] = React.useState([val]); const handl ...

Content within the Grouped Bar Graph Bar D3.js

I referred to https://bl.ocks.org/mbostock/3887051 and customized the bar chart by adding text inside each bar representing a count, such as Upstream is 50, so the number 50 should appear in the bar itself. Despite trying solutions from resources like D3. ...

What could be causing the error "styled is not defined as a function" while creating my component library using Rollup?

Currently, I am facing an issue with my component library which is built using React, styled-components, framer-motion, Rollup, and Storybook. The library is being consumed by a NextJS website, but when trying to use it, I keep encountering the following e ...

The results from utilizing Mongoose's text search feature are inaccurate and not matching the expected

Currently, I am in the process of developing a recipe blog website using Mongoose, Node.js, and Express. However, I have encountered an issue with the text search functionality not producing the desired output. In my Recipe.js schema, I have included spec ...

Learn how to create a half and half color scheme in an HTML table

I have created an HTML table that resembles a calendar. Various events are registered in the calendar, each distinguished by its color. However, I am looking to change the colors of the cells to be half and half. https://i.sstatic.net/gaQq2.png The imag ...

What is the best way to display a list of items in Vue JS while maintaining the

Looking to display my Vue.js list in reverse order using v-for without altering the original object. The default HTML list displays from top to bottom, but I want to append items from bottom to top on the DOM. Telegram web messages list achieves this wit ...

Issues encountered while retrieving JSON data from a URL using port 88

There is a URL for IPTV that returns JSON data. The URL will expire after 24 hours, so there's no risk of misuse. http://mytv-extra.com:88/player_api.php?username=4240670294&password=0301902562&action=get_live_streams&category_id=3045 Wh ...

Troubleshooting: Why is my console.log not working in JavaScript

Recently, I've been diving into the world of JavaScript, but for some reason, I can't seem to make console.log function properly. At the top of my HTML document in the head section, I added jQuery like this: <script type="text/javascript" sr ...

Ways to extract a single digit from the total sum of a date in the format of 15-06-2015

Is there a way to extract a single digit from the sum of a number in date format, such as 15-06-2015? My goal is to convert the date format 15-06-2015 into a single-digit value by adding up the numbers. For instance: In the case of 15-05-2015, the output ...

Having trouble debugging localhost because the cookie for a specific domain is not being written

In a particular scenario, I needed to write a cookie upon logging in with a code for a specific domain, for example, let's say the domain is "uat.example.com." The backend API will generate this cookie after authenticating the user, and then the appl ...

Tips for inserting text to the left rather than the right using Jquery

I recently came across this code snippet shared by some helpful users on stackoverflow and it has been working perfectly for me. However, I do have a couple of queries regarding its functionality. Firstly, how can I ensure that the current selected option ...

Difficulty encountered when choosing and interacting with website button with the utilization of Python 3.5.1 and Selenium 2.53.2

I am currently utilizing a Macbook Air that runs on OS X El Capitan. My tool of choice is Python IDLE, and I am attempting to target and interact with the button located on the webpage below: <div class="search-form-actions"> <button class="btn ...

Display the results of the SQL query in a graphical chart

I'm a beginner when it comes to C#, so please bear with me if this question seems basic. I've searched on Google, but couldn't find a solution. I've recently started a new project in Visual Studio (SharePoint 2016 Empty Project with a ...

The string retrieved from the server is showing special characters as "?"

I am facing an issue with my servlet where it retrieves data from Cloud SQL, converts it to a Java object, and then converts it to JSON before appending it to the response writer. The problem arises when the data contains special characters like "รง" and ...